0
<?php
require_once("db_connect.php");
$arr = $_GET['arr'];
$selected_header = implode(', ', (array)$arr);
$sql = "SELECT $selected_header FROM release_ ORDER BY id DESC";
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename=CNC-'.date('Ymd').'.xls');
header('Pragma: no-cache');
header('Expires: 0');
$output = '';
$output .= '<table><tr>';
$header_arr = explode(',', $arr);
$len = count($header_arr);
for($a=0; $a<$len; $a++){
$output .= "<th style='width: 100px; text-align: center;'>" . $header_arr[$a] . "</th>";
}
$output .= '</tr>';
$res = mysqli_query($conn, $sql);
/*====this ruins everything=====*/
while($row = $res->fetch_assoc()){
$output = '<tr align="center">';
for($a=0; $a<$len; $a++){
$output .= "<td>" . $header_arr[$a] . "</td>";
}
echo "</tr>\t\n";
}
/*===============================*/
$output .= '</table>';
echo $output;
?>엑셀 가져 오기
내가 얻을 엑셀 파일의 헤더를 표시 할 수 모르지만, 내용이 전혀 표시되지 않습니다. 행 태그의 전체 문자열이 표시됩니다. 파일에서 Excel로 데이터베이스의 데이터를 어떻게 표시 할 수 있습니까? 도와주세요. 나는 내 프로젝트 (CakePHP의)이 자신의 방법처럼 사용할 수 있습니다에서 수행 한
코드가 실제로 HTML 테이블을 구축 것 같습니다. Excel 파일을 원한다면 PHPExcel과 같은 라이브러리를 사용해야합니다. –
@MDB는 쿼리에서 올바르게 실행되는 쿼리입니다. 특히이 릴리스는 무엇입니까? 너의 테이블 이름 이니? – rahul