웹마스터 팁

<?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 에서 테스트 했습니다.

 

제목 글쓴이 날짜
EXIF 메타정보 필요하신 분 있으시면 forest535 2018.04.09
게시판 본문읽기에서 컨텐츠 이미지와 텍스트 분리하여 출력하기 forest535 2018.04.09
관리권한 없이도 특정그룹에게 비밀글 열람 및 댓글작성 권한 부여하는 방법 ( 부운영자등을 위해) sejin7940 2018.04.26
[PHP] 이름 및 연락처 마스킹 처리 [1] ppumweb 2018.05.21
단축url API 사용하시는 분들... 미스터강 2018.06.01
게시판글 엑셀 파일 보내기 php7용 file 황금날개 2018.06.05
도메인 변경 또는 설치 폴더 변경시 이미지 주소변경하기 file 해피정닷컴 2018.06.08
XE용 CKEditor v4.9.2 (다크 스킨 수정) [4] file 큰돌♡ 2018.07.04
DB를 손쉽게 관리 [1] EISOFT 2018.07.15
Code-Highlighter 3.0.83 가로 스크롤바를 어디론가 보내 버리고 싶으신 분. 달빛늑대 2018.07.16
Google 스프레드시트에서 구글 번역으로 XE 다국어 내용 만들기(Lang.xml 용도) file 달빛늑대 2018.07.17
act로 다른 페이지 보여주기 [1] 이온디 2018.07.25
다른 서버 간 서브도메인 쿠키 공유 에이트 2018.08.04
썸네일 방식으로 이미지 원본 주소 가져오기 에이트 2018.08.22
PHP 뮤텍스 락 설치법(memcached 활용) [1] 에이트 2018.09.03
PHP 뮤텍스 락 설치법(redis 활용) 에이트 2018.09.11
무료 psd, html 탬플릿, 아이콘 사이트공유합니다. 허허길드짱 2018.11.27
file 모듈 insertFile() manual_insert 시 디렉토리생성 에러 문제 해결 방법 onTrust 2019.01.02
트윗버튼, 페어스북 좋아요 버튼, 카카오스토리 좋아요 버튼 태그 elancer 2019.03.11
무료이미지 다운 받을 수 있는 곳 elancer 2019.03.19