Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > สอบถามครับ เมื่อ Export excel ข้อมูลจากฐานข้อมูลแล้วตามวันที่ แต่ excel ที่ได้คือข้อมูลทั้งหมด แก้ไขอย่างไรได้บ้างครับ



 

สอบถามครับ เมื่อ Export excel ข้อมูลจากฐานข้อมูลแล้วตามวันที่ แต่ excel ที่ได้คือข้อมูลทั้งหมด แก้ไขอย่างไรได้บ้างครับ

 



Topic : 136640



โพสกระทู้ ( 1 )
บทความ ( 0 )



สถานะออฟไลน์




php1

จากรูป เมือกำหนดวันที่เพื่อจะแสดงข้อมูลที่จะ export เป็น excel file แล้วได้ครับ
แต่กด export ข้อมูลใน excel เป็นข้อมูลทั้งหมดในฐานข้อมูลเลยครับ จะแก้ไขอย่างไรให้เป็นตามข้อมูลที่เราเลือกไว้ตามวันที่ครับ

Code หน้าค้นหาข้อมูลเพื่อ export excel
Code
<?php session_start(); //ประกาศใช้ session //เรียกใช้ไฟล์ config.ini.php include "config.ini.php"; if(isset($_GET['act'])){ if($_GET['act']== 'excel'){ header("Content-Type: application/xls"); header("Content-Disposition: attachment; filename=export.xls"); header("Pragma: no-cache"); header("Expires: 0"); } } $where=""; $mess=""; //รับค่าตัวแปร วันที่ //if ($_POST["sd"]!=1 and $_POST["sm"]!=1) { $stdate=$_POST["stdate"]; $where=" where customer_date>='$stdate' "; $mess=" <strong>Start date : </strong> ".$stdate; /*} if ($_POST["ed"]!=1 and $_POST["em"]!=1) {*/ $endate=$_POST["endate"]; $where.=" and customer_date<='$endate' "; $mess.="&nbsp;&nbsp; <strong>End date : </strong> ".$endate; //} //select ข้อมูลรายการขายสินค้าจากฐานข้อมูล orders $sql=" select * from tb_customer $where order by customer_id desc "; $result=mysql_query($sql); ?> <!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="nofollow"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <style> body { background-color:#E7E9EB; } #myDIV { width:100%; height:650px; background-color:#FFFFFF; border:5px solid; border-style: outset; } #myDIV2 { width:100%; height:850px; background-color:#FFFFFF; border: 1px solid black; border-bottom-right-radius:40px; } </style> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> <title>- CUSTOMER -</title> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <!-- Optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <!-- Latest compiled and minified JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <script language="javascript"> function chk_form() { var Rtn=true; if (document.getElementById("stdate").value=="" || document.getElementById("endate").value=="") { Rtn=false; alert('Please enter complete date information.'); } return Rtn; } </script> </head> <body> <div class="container"> <div class="row"> <div class="col-md-12"> <h4> - CUSTOMER -</h4> <table width="100%" border="0" align="right"> <tr> <td width="167" align="right" valign="top"><div align="justify"> <div class="col-md-6"> <div align="right"><a href="index.php"> <button class="btn btn-danger" data-toggle="modal" style="height:50px;width:200px">Back to Homepage</br></button></a></div> <div align="right"><a href="add_customer.php"> <button class="btn btn-info" data-toggle="modal" style="height:50px;width:200px">Add Customer</br></button></a></div> <div align="right"><a href="manage_cus.php"> <button class="btn btn-info" data-toggle="modal" style="height:50px;width:200px">Manage All</br></button></a></div> <div align="right"><a href="download_customer.php"> <button class="btn btn-info" data-toggle="modal" style="height:50px;width:200px">Download</br></button></a></div> </div> </div> <div id="myDIV" align="justify"> <!-- form สำหรับค้นหาข้อมูล --> <form class="form-inline" name="frmSearch" method="post" action="search.php"> <table width="20%" height="238" border="0" class="table table-hover"> <tr> <td> <div class="form-group"> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> </p> <tr> <td height="85" valign="top"></td> </tr> </table> </form> </div></td> <td width="80%" align="center" valign="top"> <p>&nbsp;</p> <form id="form1" name="form1" method="post" action="rtp_cus.php" onsubmit="return chk_form()" target="_new"> <table width="100%" border="1" class="table table-striped table-bordered table-hover"> <tr class="info"> <td width="120"><div align="right"><strong>Start date :</strong></div></td> <td width="150"> <input name="stdate" type="date" id="stdate" size="10"> </td> <td width="100"><div align="right"><strong>End date:</strong></div></td> <td width="150"><input name="endate" type="date" id="endate" size="10"></td> </tr> <tr> <td align="center" colspan="4"> <p> <input type="submit" name="button2" id="button2" value="Search"> </p> </td> </tr> </table> </form> <p>&nbsp;</p> <p>&lt;<?php echo $mess; ?>&gt;</p> <form id="form2" name="form2" method="post" action="export_cus.php"> <p><input type="submit" name="export" id="export" value="Export" ></p> <p></p> <table align="center" class="table table-striped table-bordered table-hover"> <thead> <tr class="info"> <th width="10%"><div align="center">No.</th> <th width="20%"><div align="center">Customer Code</th> <th width="20%"><div align="center">Item No.</th> <th width="10%"><div align="center">Period date </th> <th width="15%"><div align="center">Business group</th> <th width="10%"><div align="center">Detail</th> </tr> <?php if (mysql_num_rows($result) > 0) { ?> <?php for ($i=1;$i<=mysql_num_rows($result);$i++) { $rs = mysql_fetch_array($result); $sql2=" select * from tb_dept where dept_id=$rs[dept_id] "; $result2=mysql_query($sql2); $rs2=mysql_fetch_array($result2); ?> </thead> <tr> <td><div align="center"><?php echo $i?></div></td> <td><div align="center"><?php echo $rs['customer_code']?></div></td> <td><div align="center"><?php echo $rs['item_no']?></div></td> <td><div align="center"><?php echo $rs['customer_date']?></div></td> <td><div align="center"><?php echo $rs2['dept_name']?></div></td> <td><div align="center"><a target ="_blank" href="view_customer.php?id_view=<?php echo $rs["customer_id"]; ?>" ><button class="btn btn-success btn-xs" data-toggle="modal">View</button></a></div></td> </tr> <?php } ?> </table> </form> <?php } else { ?> <table width="300" border="0" align="center" cellpadding="0" cellspacing="2"> <tr></tr> <tr><td><div align="center"><font size="+1">ไม่พบข้อมูล</font></div></td> </tr> <tr> </tr> </table> <?php } ?> <p>&nbsp; </p> <td height="158"></td> </tr> </table> <p>&nbsp; </p> <tr> <div class="modal-footer"> <td height="113" colspan="6"><div align="center"></div></td> </div> </tr> </td> </body> </html>


Code เมื่อกด export save เป็น excel
Code
<?php set_time_limit(0); header('Content-Type: text/html; charset=utf-8'); header("Content-Type: application/vnd.ms-excel"); header('Content-Disposition: attachment; filename="filename.xls"');#กำหนดชื่อไฟล์ echo '<html xmlns:o="urn:schemas-microsoft-com:office:office"xmlns:x="urn:schemas-microsoft-com:office:excel"xmlns="http://www.w3.org/TR/REC-html40">'; //ทำการดึงข้อมูลจาก Database //Connect DB include "config.ini.php"; $sql=mysql_query("select * from tb_customer where customer_id "); $num=mysql_num_rows($sql); ?> <html xmlns:o="urn:schemas-microsoft-com:office:office"xmlns:x="urn:schemas-microsoft-com:office:excel"xmlns="http://www.w3.org/TR/REC-html40"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <strong>Customer Report date <?php echo date("d/m/Y");?> All <?php echo number_format($num);?> code</strong><br> <br> <div id="SiXhEaD_Excel" align=center x:publishsource="Excel"> <table x:str border=1 cellpadding=0 cellspacing=1 width=100% style="border-collapse:collapse"> <tr> <td width="200" align="center" valign="middle" ><strong>Customer code</strong></td> <td width="181" align="center" valign="middle" ><strong>Item no</strong></td> <td width="181" align="center" valign="middle" ><strong>Period date</strong></td> <td width="181" align="center" valign="middle" ><strong>Business group</strong></td> <td width="185" align="center" valign="middle" ><strong>Total qulity</strong></td> <td width="185" align="center" valign="middle" ><strong>Total amount</strong></td> </tr> <?php if($num>0){ while($row=mysql_fetch_array($sql)){ $sql2=" select * from tb_dept where dept_id=$row[dept_id] "; $result2=mysql_query($sql2); $rs2=mysql_fetch_array($result2); ?> <tr> <td align="center" valign="middle" ><?php echo $row['customer_code'];?></td> <td align="center" valign="middle"><?php echo $row['item_no'];?></td> <td align="center" valign="middle"><?php echo $row['customer_date'];?></td> <td align="center" valign="middle"><?php echo $rs2['dept_name'];?></td> <td align="center" valign="middle"><?php echo $row['total_qty'];?></td> <td align="center" valign="middle"><?php echo $row['total_amt'];?></td> </tr> <?php } } ?> </table> </div> <script> window.onbeforeunload = function(){return false;}; setTimeout(function(){window.close();}, 10000); </script> </body> </html>




Tag : PHP, HTML, CSS, HTML5, XAMPP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2022-03-30 15:01:47 By : babablue.blue View : 769 Reply : 2
 

 

No. 1



โพสกระทู้ ( 4,706 )
บทความ ( 8 )



สถานะออฟไลน์


sql ไม่ตรงกันมันก็ให้ผลลัพธ์ไม่เหมือนกัน หน้าที่แสดงผลถูกใช้ยังไงลอง echo ออกมาดู
หน้าที่แสดงผลไม่ถูกไม่ตรงใช้ยังไงลอง echo ออกมาดู






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2022-03-31 05:23:18 By : mr.v
 


 

No. 2



โพสกระทู้ ( 3,843 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Twitter Facebook

ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.v เมื่อวันที่ 2022-03-31 05:23:18
รายละเอียดของการตอบ ::
ตามนี้เลยครับ
Sql query ใน ตาราง where อะไร ตอนไป ทำ query export ให้ where เหมือนกันครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2022-03-31 07:48:23 By : mongkon.k
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถามครับ เมื่อ Export excel ข้อมูลจากฐานข้อมูลแล้วตามวันที่ แต่ excel ที่ได้คือข้อมูลทั้งหมด แก้ไขอย่างไรได้บ้างครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่