|
 |
|
สอบถาม เกี่ยวกับ code ครับ จะ export ข้อมูล เป็นไฟล์ excel แล้วไม่ได้ ครับ |
|
 |
|
|
 |
 |
|
กด export แล้ว ได้ไฟล์ excel ออกมาแต่ ข้อมูลไม่มา
หน้า excelnow.php
Code (PHP)
<?
/*
Conditioned search and export to Excel file
source : http://snipplr.com/view.php?codeview&id=16324
*/
//----------- แก้ไข ส่วนที่ 1-------------------------
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "1234";
$dbname = "wanornit2";
$dbtable = "computer";
//-----------------------------------------------------
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
function xlsWriteLabel($Row, $Col, $Value ) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}
$dbc = mysql_connect( $dbhost , $dbuser , $dbpass ) or die( mysql_error() );
mysql_select_db( $dbname );
// ------------------ แก้ไข ส่วนที่ 2-------------------------------------------------
$q = "SELECT * FROM ".$dbtable." WHERE '".$_GET['st']."%' LIKE '".$_GET['en']."%'";
// -------------------------------------------------------------------------------------
mysql_query("SET CHARACTER SET tis620");
$qr = mysql_query( $q ) or die( mysql_error() );
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment;filename=excel_".$dbtable.".xls "); // <==แก้ไข ส่วนที่ 3
header("Content-Transfer-Encoding: binary ");
xlsBOF();
$col = 0;
$row = 0;
$first = true;
while( $qrow = mysql_fetch_assoc( $qr ) )
{
if( $first )
{
foreach( $qrow as $k => $v )
{
xlsWriteLabel( $row, $col, strtoupper( ereg_replace( "_" , " " , $k ) ) );
$col++;
}
$col = 0;
$row++;
$first = false;
}
foreach( $qrow as $k => $v )
{
xlsWriteLabel( $row, $col, $v );
$col++;
}
$col = 0;
$row++;
}
xlsEOF();
exit();
?>
ผิดตรงไหน ส่วนไหน รบกวนทีนะครับ
ขอบคุณครับ
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2013-04-19 11:47:48 |
By :
ppichimaru |
View :
952 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 01
|