웹마스터 팁

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
//url 로 직접 불러오는것을 방지
if(!strstr($_SERVER['HTTP_REFERER'],$_SERVER['SERVER_NAME'])&& !strstr($_SERVER['HTTP_REFERER'],'out_excel.php')) exit;
 
$info array(
"host" => "localhost",
"user" => "db명",
"pass" => "db비번",
"db" => "xe테이블명",
"table" => "xe_documents",
"module_srl" => "출력할게시판slr",
);
$getFields array("title","regdate","content"); //출력원하는 칼럼을 배열로 입력
 
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=doc_".date('Ymd').".xls");
 
$con = mysql_connect($info[host], $info[user], $info[pass]) || die(mysql_error());
mysql_query("set names utf8");
$con_db = mysql_select_db($info[db]) || die(mysql_error());
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv=Content-Type content=text/html; charset="utf-8">
</head>
<body>
<table border=1>
<tr align=center>
 
<?php
//제목 불러오기
$fields = mysql_list_fields("$info[db]""$info[table]");
$columns = mysql_num_fields($fields);
 
for$i=0 ; $i<$columns $i++ )
{
    $field[$i]=mysql_field_name($fields$i);
    if( in_array($field[$i], $getFields) ) echo "<th>".$field[$i]."</th>";
}
 
//확장변수의 타이틀은 값이므로       
$result = mysql_query("select  var_name from xe_document_extra_keys where module_srl = $info[module_srl]");                  
while$data = mysql_fetch_array($result) )
{                          
    echo "<th>".htmlspecialchars($data[var_name])."</th>";
}  
 
echo"</tr>";             
 
 
//데이터 불러오기
$result = mysql_query("select * from $info[table] where module_srl = $info[module_srl]");
while$data = mysql_fetch_assoc($result) )
{
    echo"<tr>";
    foreach$data as $key => $val )
    {
        if( in_array($key$getFields) ) 
        {
            if ($key ==  'regdate') { 
                echo "<td   style='mso-number-format:\"0_ \";' >".htmlspecialchars($val)."</td>";               
            }elseif ($key ==  'content'){       //내용 출력할경우 태그가 그대로 출력됨         
                //echo "<td>".$val."</td>";     //셀이 두칸이상으로 늘어남
                echo "<td >".htmlspecialchars(strip_tags(str_replace(" ","",$val)))."</td>";
            }else {
                echo "<td>".htmlspecialchars($val)."</td>";
            }  
        }
 
        if ($key ==  'document_srl'){           //확장변수 불러올때 사용
            $d_srl=$val;
        }
 
    }
                //확장변수 출력 ////////////////////////////////////////////
                //eid리스트를 불러온다
                $query=mysql_query("select eid from xe_document_extra_keys where module_srl = $info[module_srl]");      
                while($extra_title=mysql_fetch_array($query))
                {      
                    echo"<td>";
 
                    $egetFields array("value","eid");  
                    //확장변수 값을 불러와 eid값이 같은곳에 출력
                    $extra_result = mysql_query("select * from xe_document_extra_vars where document_srl = $d_srl");  
                    while$edata = mysql_fetch_assoc($extra_result) )
                    {
                        $extra_str="";
                        foreach$edata as $key => $val ){
                            if( in_array($key$egetFields) ){                          
                                $extra_str $val.",".$extra_str;
                            }
                        }
 
                        $extra_arr=explode(",",$extra_str);                                
                        if ($extra_title[eid]==$extra_arr[0]){
 
                            //전화번호값은 "|@|" 를 "-" 로 변경
                            if($extra_title[eid]=="mb_phone_Number"){
                                echo str_replace("|@|","-",htmlspecialchars($extra_arr[1]));
 
                            //기타 배열값들은 ',' 로 변경
                            }elseif($extra_title[eid]=="mb_incomplete"||$extra_title[eid]=="mb_cs"){
                                echo str_replace("|@|",",",htmlspecialchars($extra_arr[1]));
                            }else{
                                echo htmlspecialchars($extra_arr[1]);                     
                            }
                        }
                    }
 
                    echo"</td>";   //eid값이 없으면 빈칸입력
                }              
                /////////////////////////////////////////////////////////////////////
 
    echo"</tr>";
}
 
 
?>
</table>
</body>
</html>


확장변수 출력부분만 끼워넣었습니다.

 

url로 실행안되고 사이트내에서 링크로 불러오게 했고요

 

저 같은경우는 리스트 아래 검색버튼옆에 버튼방식으로 추가해서 사용중입니다.(루트에 위 php 파일이 있고)

 

<a cond="$grant->manager" class="btn" href="out_excel.php" title="엑셀 출력"> 엑셀출력</a>

 

전화번호출력과 기타배열들 출력부분은 해당 확장변수 eid값으로 변경해주시면됩니다.

 

 

제목 글쓴이 날짜
content 위젯에서 태그로 글 뽑기 날아올라 2021.02.07
[PHP] 이름 및 연락처 마스킹 처리 [1] ppumweb 2018.05.21
Windows10 에서 IIS + mysql + PHP 설치 [10] file HSJI 2014.07.21
코드 이미지 생성해주는 사이트 [2] file reactux 2019.10.06
XE를 다른디렉토리에 설치후 리다이렉트하기 디자인플렉스 2020.04.24
게시판 글 엑셀로 출력하기(확장변수 포함) [15] 한이73 2014.07.17
관리자 아이디/비번을 잃어버렸을때, 관리자페이지 접속을 못할 때 TIP [1] file 플레이웹 2019.08.13
커뮤니션 쪽지 보내기 기능을 모바일 에서 실행시 로그인 풀림 현상 인천한량 2020.04.14
nginx 에서 서브도메인 사용시 로그인유지방법 [3] garnecia 2014.02.26
IIS에서 HTTPS를 사용하기 위한 SSL설정 (letsencrypt 인증서 설치, 갱신) file ehii 2016.04.13
AI 개발에 적합한 5가지 프로그래밍 언어 ppumweb 2020.01.06
날씨배너 600종류 입니다.(지역별75종X색상별8종) file 푸른커튼 2008.01.30
대부분 쉬운설치로 인해 홈페이지 빈 페이지가 뜨는 에러는.. CJM 2019.10.24
xe 기본회원가입품 연락처항목 공백&숫자 유효성검사 질문입니다. 해운거사2 2019.08.25
[주옥시리즈] 내글 모니터링, 작성글 앞으로 뺴기 [6] socialskyo 2013.10.18
회원가입품 연락처항목 공백잇을시 질문입니다. 해운거사2 2019.08.16
VSCODE에서 PRETTIER-PHP 사용하기 (중급자용) reactux 2019.07.29
관리자페이지의 회원목록에서 타회원들의 비밀번호 찾기 질문/답변 수정 가능하도록 하려면.. sejin7940 2019.07.03
XE 코어의 메일전송을 우리알림 모듈로 대체하는 방법 [30] file GG 2014.11.24
XE 1.5.1로 사이트 꾸미기 Part 2 [11] file 황비 2011.12.06