웹마스터 팁

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

 

제목 글쓴이 날짜
최신이미지 추출시 사진 아래 내용들 중간 정돈 방법 [4] file 팔공산 2007.08.23
상단메뉴 개수를 지정한 만큼만 보여주고자 할 경우 [9] 똑디 2007.08.23
여러 개의 메뉴를 달아보자! [5] file 고라리 2007.08.23
제로보드 관리자 레벨이 관리자 레벨로 안나올때 [5] 나무넷 2007.08.23
위지웍에디터가 갑자기 작동을 안할때 팔공산 2007.08.23
w3c.org의 웹페이지 유효성 검사기 file 바람처럼831 2007.08.24
(달력/Archive 문제해결법) 날짜로 검색하는 것이 제대로 안될때 [8] 베니 2007.08.25
확장변수 [2] 다케루 2007.08.25
0.1.1 패치하시면 가입시 기본 회원 그룹 선택해야해요. [2] 다케루 2007.08.26
로그인 불가 - APM 관리자일 때 (일반적인 경우 아님) [3] Sx3 2007.08.26
플래쉬 화일을 헤더와 푸터에 넣어보기 [11] file choi2007 2007.08.27
분류(카테고리) 색상 지정하기. [12] file 송암 2007.08.27
올블로그에서 제로보드가 깨질때.. [1] file 스컬리지금어디야 2007.08.27
홈페이지에 게시판을 iframe, include로 이용하시는분들 느까끼 2007.08.27
썸네일 크기 줄이는 법 [6] 느까끼 2007.08.27
템플릿 컴파일 파일 지우기 귀찮을때 [1] 젬스송 2007.08.28
최신댓글에 닉네임 출력하기... [5] 똑디 2007.08.28
템플릿 파일에서 일반 PHP 코드 사용 [3] 화니군 2007.08.28
게시판 분류(카테고리)를 텍스트&이미지로 나열 하기 [11] Simulz 2007.08.29
xe_layout 을 자신의 웹 첫화면과 연결 [2] justrue 2007.08.29