웹마스터 팁

<?php
//url 로 직접 불러오는것을 방지
 if(!strstr($_SERVER['HTTP_REFERER'],$_SERVER['SERVER_NAME'])&& !strstr($_SERVER['HTTP_REFERER'],'out_excel.php')) exit;
 
$servername = "localhost";
$username = "user ID";
$password = "DB_password";
$table = "xe_documents";
$database = "DB name";
$module_srl = "module srl"; // 숫자 입력

$con = new mysqli($servername,$username,$password,$database);

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$getcolumns = array("title"); //출력원하는 칼럼을 배열로 입력
 
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=doc_".date('Ymd').".xls");
 

?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<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

//제목 불러오기

$sql = "SHOW COLUMNS FROM $database.$table";
$dbcolumns = mysqli_query($con,$sql); //xe_documents에서 칼럼값 불러오기

// fetch associative array
while ($rowname = mysqli_fetch_row($dbcolumns)) {
    if( in_array($rowname[0], $getcolumns) ) echo "<th>".$rowname[0]."</th>";
}

//확장변수의 타이틀은 값이므로      
$result = mysqli_query($con, "select var_name from xe_document_extra_keys where module_srl = $module_srl");                 
while( $data = mysqli_fetch_array($result) ){                         
    echo "<th>".htmlspecialchars($data[var_name])."</th>";

 
echo"</tr>";

//데이터 불러오기
$result = mysqli_query($con, "select * from $table where module_srl=$module_srl");
while( $data = mysqli_fetch_assoc($result) ){
    echo"<tr>";
    foreach( $data as $key => $val ){
        if( in_array($key, $getcolumns) ){
            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=mysqli_query($con, "select eid from xe_document_extra_keys where module_srl = $module_srl");     
 while($extra_title=mysqli_fetch_array($query)){     
  echo"<td>";
  $egetFields = array("value","eid"); //확장변수 값을 불러와 eid값이 같은곳에 출력
  $extra_result = mysqli_query($con, "select * from xe_document_extra_vars where document_srl = $d_srl"); 
  while( $edata = mysqli_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>";
}
 
mysqli_close($con);

?>
</table>
</body>
</html>

------------------------------------------------------------------------------------------------------------------

https://www.xpressengine.com/index.php?mid=tip&search_target=title_content&search_keyword=%EC%97%91%EC%85%80&document_srl=22795784

글을 조금 수정해서 php7에서 사용할 수 있도록 했습니다.

만약, 오류가 나더라도 답변할 실력이 안됩니다.

centos 7, php7.2 에서 테스트 했습니다.

 

제목 글쓴이 날짜
새로운 쪽지 유무에 따라 이미지 변경하는 법 [2] 멀티비타민 2013.12.16
관리권한 없이도 특정그룹에게 비밀글 열람 및 댓글작성 권한 부여하는 방법 ( 부운영자등을 위해) sejin7940 2018.04.26
게시판 본문읽기에서 컨텐츠 이미지와 텍스트 분리하여 출력하기 forest535 2018.04.09
EXIF 메타정보 필요하신 분 있으시면 forest535 2018.04.09
XEDITON 레이아웃에 다국어(국기) 선택 버튼 추가하기 [7] file ehii 2015.04.15
댓글을 역순으로 출력하는 팁 (최근댓글이 가장 위에) [8] sejin7940 2012.02.10
게시글 상하단에 광고삽입하기 veplay2 2018.03.08
winamp 방송정보 알아오기 (2005년 새로 코딩한 버전) [8] file 이승원 2005.05.06
[강추]!! 긁어와서 [자동]으로 게시글로!! [메타 블로그] php 로 넣기!!! xe블로그api를 이용한.. [51] file 김기철980 2009.01.29
css팁 : 웹폰트 저장소 Dotcomsoft 2018.01.17
css 팁 : 색상코드 검색이필요할때 Dotcomsoft 2018.01.17
모바일에서 유투브 동영상 크기 300px고정 [28] 패시브 2012.07.31
XE에 채팅 연동 하기 [1] younggyo 2017.12.15
bitnami ssl 클라우드플레어 설정법 키큰아이 2017.12.06
성공적인 홈페이지 제작을 위해 점검해야 될 사안 웹369 2017.12.05
제로보드에서 iframe 높이 자동(유동적)조절(파폭,IE, 오페라,사파리,IETester) [11] file hhgyu 2010.09.17
통합검색의 기본값을 '제목' 이 아니라 '제목+내용' 으로 하고 픈 경우 [2] sejin7940 2017.02.24
모바일앱, 모바일 어플에서 카카오톡, 카카오 스토리 앱으로 공유하기 한꼬마 2017.10.31
폰갭 모바일 사진 분석 부터 번역까지 아토피뉴스 2017.10.16
사랑비Bgm 플레이기 설치하고 제어하기 [5] file 팔공산 2008.11.22