mysql db를 excel 파일로 변환하기

<?
$connect_host        = “localhost”;
$connect_id        = “user_id”;
$connect_pass        = “password”;
$connect_db        = “engrid”;
$connect_table        = “table_name”;
$xls_filename        = “filename.xls”;


$connect=@mysql_connect($connect_host,$connect_id,$connect_pass);
$mysql=@mysql_select_db($connect_db,$connect);


header(“Content-Type: application/vnd.ms-excel”);
header(“Content-Disposition: attachment; filename=$xls_filename”);
?>


<html>
<head>
<meta http-equiv=Content-Type content=text/html; charset=EUC-KR>
</head>
<body>
<table border=1>
<tr align=center>
<?
$fields = mysql_list_fields(“$connect_db”, “$connect_table”);
$columns = mysql_num_fields($fields);


for ($i = 0; $i < $columns; $i++) {
$field[$i]=mysql_field_name($fields, $i);
  echo “<th>”.$field[$i]. “</th>”;
}
?>
</tr>


<?
$result=mysql_query(“select * from $connect_table”);
while($data=mysql_fetch_assoc($result)){
echo”<tr>”;


for ($i = 0; $i < sizeof($field); $i++) {
echo “<td>”.$data[“$field[$i]”].”</td>”;
}


echo”</tr>”;
}
?>
</table>
</body>
</html>
~

서진우

슈퍼컴퓨팅 전문 기업 클루닉스/ 상무(기술이사)/ 정보시스템감리사/ 시스존 블로그 운영자

You may also like...

3 Responses

  1. 2024년 9월 13일

    … [Trackback]

    […] Read More to that Topic: nblog.syszone.co.kr/archives/3354 […]

  2. 2024년 9월 20일

    … [Trackback]

    […] Read More to that Topic: nblog.syszone.co.kr/archives/3354 […]

  3. 2024년 11월 11일

    … [Trackback]

    […] Read More Information here to that Topic: nblog.syszone.co.kr/archives/3354 […]

페이스북/트위트/구글 계정으로 댓글 가능합니다.