PHP & Others

DB내용 EXCEL로 변환

컨텐츠 정보

본문

헤더 써서 하거나, csv로 파일 만들거나..

<?
require_once("dbconn.php");

header( "Content-type: application/vnd.ms-excel" );
header( "Content-Disposition: attachment; filename=myfile.xls" );
header( "Content-Description: PHP4 Generated Data" );

$sql = "SELECT * FROM tableName";
$stmt = mysql_query("$sql",$conn) or die(mysql_error());
while ($row = mysql_fetch_row($stmt)){
echo ("$row[0] $row[1] $row[2] $row[3] ... \\r\\n");
}
mysql_free_result($stmt);
mysql_close($conn);
?>

tip & tech 에서 검색해서 참고하기

관련자료

댓글 0
등록된 댓글이 없습니다.
Today's proverb
만일 당신이 배를 만들고 싶다면 사람들을 불러모아 목재를 가져오게 하고 일을 지시하고 일감을 나눠 주는 등의 일을 하지 말아라. 대신 그들에게 저 넓고 끝없는 바다에 대한 동경심을 키워 줘라. (생텍쥐페리)