|
 |
|
การทำ PHP => ExcelExport จาก Searching ส่ง _GET จากหน้า Searching ไปยัง generate Excel ตามเงื่อนไข |
|
 |
|
|
 |
 |
|
แสดงว่าทำการ export ออกมาได้แล้วใช่มั้ยครับ แต่เป็นตัวอักษรที่อ่านไม่ออกเท่านั้น....
ให้ดูเรื่องการ encode ว่าถูกต้องหรือเปล่า ถ้าเป็นการใช้ framework ให้ดูจาก reference ของแต่ละ framework ครับ.....
|
 |
 |
 |
 |
Date :
2011-12-06 10:57:26 |
By :
Songkram |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูพวก iconv() ด้วยครับ 
|
 |
 |
 |
 |
Date :
2011-12-06 11:01:42 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
mysql_query(SET CHARACTER SET TIS620);
เอาไปต่อจาก บรรทัดที่ 16
|
 |
 |
 |
 |
Date :
2011-12-06 11:30:08 |
By :
บังเอิญผ่านมาเห็น |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีปัญหาอีกแล้วครับ ข้อมูลที่ export ออกมาไม่เป็นตามเงื่อนไขครับ มันออกมาหมดเลยครับ

Export

|
ประวัติการแก้ไข 2011-12-06 13:54:52 2011-12-06 14:03:44 2011-12-06 14:04:31
 |
 |
 |
 |
Date :
2011-12-06 13:52:16 |
By :
sbruang |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
code ฝั่ง search ครับ
Code (PHP)
<html>
<head>
<title>Excel Export</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form name="frmSearch" method="post" action="<?=$_SERVER['../SCRIPT_NAME'];?>">
<table width="599" border="1" align="center">
<tr>
<th>Select
<select name="ddlSelect" id="ddlSelect">
<option value="">- Select -</option>
<option value="fname" <?if($_POST["ddlSelect"]=="fname"){echo"selected";}?>>ชื่อ</option>
<option value="lname" <?if($_POST["ddlSelect"]=="lname"){echo"selected";}?>>นามสถุน</option>
<option value="groupName" <?if($_POST["ddlSelect"]=="groupName"){echo"selected";}?>>กลุ่ม/ฝ่าย</option>
<option value="j_name" <?if($_POST["ddlSelect"]=="j_name"){echo"selected";}?>>ตำแหน่ง</option>
</select>
Keyword
<input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_POST["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form>
<?
include("../config.inc.php");
conndb();
// Search By Name
$strSQL = "SELECT * FROM member ,groupdep ,job WHERE 1 and member.groupID = groupdep.groupID and member.j_id = job.j_id";
if($_POST["ddlSelect"] != "" and $_POST["txtKeyword"] != '')
{
$strSQL .= " AND (".$_POST["ddlSelect"]." LIKE '%".$_POST["txtKeyword"]."%' ) ";
}
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="613" border="1" align="center">
<tr>
<th width="91"> <div align="center">ID </div></th>
<th width="98"> <div align="center">ชื่อ</div></th>
<th width="198"> <div align="center">นามสกุล</div></th>
<th width="198"> <div align="center">ตำแหน่ง</div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center">
<?=$objResult["id"];?></div></td>
<td><?=$objResult["fname"];?></td>
<td><?=$objResult["lname"];?></td>
<td><?=$objResult["j_name"];?></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($conn);
?>
<div align="center"><br>
<input name="btnExport" type="button" value="Export" onClick="JavaScript:window.location='phpCSVMySQLExport.php';">
</div>
</body>
</html>
|
 |
 |
 |
 |
Date :
2011-12-06 14:06:45 |
By :
sbruang |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อัพหน่อยกลัวตก
|
 |
 |
 |
 |
Date :
2011-12-06 16:12:20 |
By :
sbruang |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
    
|
 |
 |
 |
 |
Date :
2011-12-07 08:22:26 |
By :
sbruang |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
SQL ใน file export เหมือนกับ SQL ใน file search หรือเปล่าค่ะ
อาจจะquery อออกมาไม่เหมือนกันหรือเปล่า
|
 |
 |
 |
 |
Date :
2011-12-07 08:46:51 |
By :
LuckyStar |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หน้า search.php
Code (PHP)
<html>
<head>
<title>Excel Export</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form name="frmSearch" method="post" action="<?=$_SERVER['../SCRIPT_NAME'];?>">
<table width="599" border="1" align="center">
<tr>
<th>Select
<select name="ddlSelect" id="ddlSelect">
<option value="">- Select -</option>
<option value="fname" <?if($_POST["ddlSelect"]=="fname"){echo"selected";}?>>ชื่อ</option>
<option value="lname" <?if($_POST["ddlSelect"]=="lname"){echo"selected";}?>>นามสถุน</option>
<option value="groupName" <?if($_POST["ddlSelect"]=="groupName"){echo"selected";}?>>กลุ่ม/ฝ่าย</option>
<option value="j_name" <?if($_POST["ddlSelect"]=="j_name"){echo"selected";}?>>ตำแหน่ง</option>
</select>
Keyword
<input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_POST["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form>
<?
include("../config.inc.php");
conndb();
// Search By Name
$strSQL = "SELECT * FROM member ,groupdep ,job WHERE 1 and member.groupID = groupdep.groupID and member.j_id = job.j_id";
if($_POST["ddlSelect"] != "" and $_POST["txtKeyword"] != '')
{
$strSQL .= " AND (".$_POST["ddlSelect"]." LIKE '%".$_POST["txtKeyword"]."%' ) ";
}
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="613" border="1" align="center">
<tr>
<th width="91"> <div align="center">ID </div></th>
<th width="98"> <div align="center">ชื่อ</div></th>
<th width="198"> <div align="center">นามสกุล</div></th>
<th width="198"> <div align="center">ตำแหน่ง</div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center">
<?=$objResult["id"];?></div></td>
<td><?=$objResult["fname"];?></td>
<td><?=$objResult["lname"];?></td>
<td><?=$objResult["j_name"];?></td>
</tr>
<?
}
?>
</table>
<div align="center"><br>
<input name="btnExport" type="button" method="get" value="Export" onClick="JavaScript:window.location='../Excel/phpExportDatabaseToExcel.php';">
</div>
<?
mysql_close($conn);
?>
</body>
</html>
หน้า Excel
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP(COM) Excel.Application Tutorial</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?
include("../config.inc.php");
conndb();
$strSQL = "SELECT * FROM member ,groupdep ,job WHERE 1 and member.groupID = groupdep.groupID and member.j_id = job.j_id";
mysql_query("SET CHARACTER SET TIS620");
$objQuery = mysql_query($strSQL);
if($objQuery)
{
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
//*** Excel Document Root ***//
$strFileName = "MyXls/MyExcel.xls";
//*** Connect to Excel.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Add();
//*** Create Sheet 1 ***//
$xlBook->Worksheets(1)->Name = "My Customer";
$xlBook->Worksheets(1)->Select;
//*** Header ***//
$xlApp->ActiveSheet->Cells(1,1)->Value = "fname";
$xlApp->ActiveSheet->Cells(1,2)->Value = "lname";
$xlApp->ActiveSheet->Cells(1,3)->Value = "lname";
$xlApp->ActiveSheet->Cells(1,4)->Value = "lname";
$xlApp->ActiveSheet->Cells(1,5)->Value = "lname";
$xlApp->ActiveSheet->Cells(1,6)->Value = "lname";
//***********//
$intRows = 2;
while($objResult = mysql_fetch_array($objQuery))
{
//*** Detail ***//
$xlApp->ActiveSheet->Cells($intRows,1)->Value = $_GET["fname"];
$xlApp->ActiveSheet->Cells($intRows,2)->Value = $_GET["fname"];
$xlApp->ActiveSheet->Cells($intRows,3)->Value = $_GET["fname"];
$xlApp->ActiveSheet->Cells($intRows,4)->Value = $_GET["lname"];
$xlApp->ActiveSheet->Cells($intRows,5)->Value = $_GET["lname"];
$xlApp->ActiveSheet->Cells($intRows,6)->Value = $_GET["lname"];
$intRows++;
}
@unlink($strFileName); //*** Delete old files ***//
$xlBook->SaveAs($strPath."/".$strFileName); //*** Save to Path ***//
//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;
}
mysql_close($conn);
?>
Excel Created <a href="<?=$strFileName?>">Click here</a> to Download.
</body>
</html>
เริ่มตรงนี้ใหม่นะครับ ถ้าสำเร็จจะเป้นประโยชน์กับหลายๆ ท่านเลย
|
 |
 |
 |
 |
Date :
2011-12-07 13:23:21 |
By :
sbruang |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
  
|
 |
 |
 |
 |
Date :
2011-12-08 08:15:57 |
By :
sbruang |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|