MySQL테이블의 내용을 엑셀파일(xls)로 다운로드 하기
컨텐츠 정보
- 21,948 조회
- 4 추천
- 목록
본문
접속된 DB의 설정된 테이블의 모든 데이터를 엑셀 파일로 다운로드 받는 소스 입니다.
/*
제작자이름 : navyism
제작자메일 : navyism@chol.com
관련사이트 : http://navyism.com
*/
<?
$connect_host = "localhost";
$connect_id = "DB아이디";
$connect_pass = "DB비밀번호";
$connect_db = "DB이름";
$connect_table = "테이블이름";
$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>
/*
제작자이름 : navyism
제작자메일 : navyism@chol.com
관련사이트 : http://navyism.com
*/
<?
$connect_host = "localhost";
$connect_id = "DB아이디";
$connect_pass = "DB비밀번호";
$connect_db = "DB이름";
$connect_table = "테이블이름";
$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>
관련자료
-
링크
댓글 0
등록된 댓글이 없습니다.