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 > สอบถามเรื่อง การออกรายงานเป็น excel ข้อมูลจากการค้นหาค่ะ



 

สอบถามเรื่อง การออกรายงานเป็น excel ข้อมูลจากการค้นหาค่ะ

 



Topic : 092454



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

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

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



สวัสดีค่ะพี่ๆทุกคน สอบถามเรื่องการออกรายงานเป็นไฟล์ excel ค่ะ

ข้อมูลที่ต้องการให้ออกรายงานเป็นข้อมูลทีได้จากการค้นหาค่ะ ปกติทำรายงานเฉพาะข้อมูลทั้งหมดในตาราง

ตามโค้ดนี้

Code (PHP)
<?
header("Content-type: application/vnd.ms-excel");
// header('Content-type: application/csv'); //*** CSV ***//
header("Content-Disposition: attachment; filename=receive_send.xls");
?>
<html>
<body>

<?
	$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
	$objDB = mysql_select_db("book");
	mysql_query("SET NAMES UTF8");
	$strSQL = "SELECT * FROM receive_send";
	$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="1000" border="0" align="center">
  <tr>
    <td align="center">หนังสือรับ - ส่งทั้งหมด</td>
  </tr>
  <tr>
    <td align="center">หน่วยงานกองช่าง</td>
  </tr>
</table>

<table width="1000" border="1" align="center">
<tr>
		<th width="120"> <div align="center">เลขที่หนังสือส่ง</div></th>
		<th width="106"> <div align="center">ลงวันที่</div></th>
        <th width="106"> <div align="center">วันที่รับ</div></th>
		<th width="138"> <div align="center">จาก</div></th>
		<th width="138"> <div align="center">ถึง </div></th>
		<th width="234"> <div align="center">เรื่อง</div></th>
		<th width="156"> <div align="center">ผู้รับ</div></th>
		<th width="156"> <div align="center">สถานะ</div></th>
        <th width="106"> <div align="center">การปฏิบัติ</div></th>

  </tr>
<?
	while($objResult = mysql_fetch_array($objQuery))
	{
?>
	<tr>
    <td height="30" align="center"><?=$objResult["send_no"];?></td>
    <td align="center"><?=$objResult["send_date"];?></td>
    <td align="center"><?=$objResult["receive_date"];?></td>
    <td align="center"><?=$objResult["receive_send_from"];?></td>
    <td align="center"><?=$objResult["receive_send_to"];?></td>
    <td align="center"><?=$objResult["receive_send_name"];?></td>
    <td align="center"><?=$objResult["receive_send_emp"];?></td>
    <td align="center"><?=$objResult["receive_send_check"];?></td>
    <td align="center"><?=$objResult["receive_send_note"];?></td>
    </tr>
<?
}
?>
</table>
<?
	mysql_close($objConnect);
?>
</body>
</html>


อยากให้ออกรายงานการค้นหาตามโค้ดนี้ ต้องแทรกโค้ดตรงไหนคะ



Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script src="js/jquery-1.9.1.min.js" type="text/javascript"></script>
		<script src="js/jquery.ui.core.js" type="text/javascript"></script>
		<script src="js/jquery.ui.datepicker.js" type="text/javascript"></script>
        <link href="css/jquery-ui.css" type="text/css" rel="stylesheet" />	
		<script type="text/javascript">
		$(function () {
			$("#datepicker-1").datepicker({ dateFormat: "yy-mm-dd" });
			$("#datepicker-2").datepicker({ dateFormat: "yy-mm-dd" });
		});
		</script>
</head>
<body>
<form name="frmSearch" method="get" action="<?=$_SERVER['SCRIPT_NAME'];?>">
  <table width="599" border="1">
    <tr>
      <th>
      ตั้งแต่วันที่<input name="start_date" type="text" id="datepicker-1" value="<?=$_GET["start_date"];?>">
      ถึงวันที่<input name="end_date" type="text" id="datepicker-2" value="<?=$_GET["end_date"];?>"> 
      <input type="hidden" name="txtKeyword" value="Act"> 
      <input type="submit" value="Search"></th>
    </tr>
  </table>
</form>
<? include("f_thaidate.php");?>
<? include("datepick/datepick.php"); ?>
<?
if($_GET["txtKeyword"] != "")
	{
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
	$objDB = mysql_select_db("book");
	mysql_query("SET NAMES UTF8");
    $strSQL = "SELECT * FROM receive_send WHERE send_date BETWEEN '".$_GET['start_date']."' and '".$_GET['end_date']."'"; 
	$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");

	?>
<table width="1000" border="1">
<tr>
		<th width="85"> <div align="center">เลขที</div></th>
		<th width="80"> <div align="center">ลงวันที่</div></th>
		<th width="95"> <div align="center">จาก</div></th>
		<th width="95"> <div align="center">ถึง </div></th>
		<th width="320"> <div align="center">เรื่อง</div></th>
		<th width="97"> <div align="center">ผู้ส่ง</div></th>
        <th width="110"> <div align="center">สถานะ</div></th>
        <th width="110"> <div align="center">การปฏิงัติ</div></th>
        <th width="40"> <div align="center">แก้ไข</div></th>
        <th width="40"> <div align="center">ลบ</div></th>

  </tr>	<?
while($objResult = mysql_fetch_array($objQuery))
{

?>
	   <tr>
		<td align="center"><?=$objResult["send_no"];?></td>
		<td align="center"><?=$objResult["send_date"];?></td>
		<td align="center"><?=$objResult["receive_send_from"];?></td>
		<td align="center"><?=$objResult["receive_send_to"];?></td>
		<td align="center"><?=$objResult["receive_send_name"];?></td>
		<td align="center"><?=$objResult["receive_send_emp"];?></td>
        <td align="center"><?=$objResult["receive_send_check"];?></td>
        <td align="center"><?=$objResult["receive_send_note"];?></td>
        <td align="center"><a href="Receive_SendEditForm.php?SendNo=<?=$objResult["send_no"];?>"><img src="images/update.png" width="22" height="22" /></a></td>
        <td align="center"><a href="JavaScript:if(confirm('ยืนยันการลบข้อมูล')==true){window.location='ReceiveDelete.php?SendNo=<?=$objResult["send_no"];?>';}"><img src="images/delete.png" width="22" height="22" /></a></td>

	  </tr>
	<?
	}
	?>
	</table>
<?
	
	mysql_close($objConnect);

	}
	
	?>

</body>







Tag : PHP









ประวัติการแก้ไข
2013-03-14 22:27:12
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-03-14 22:15:18 By : gosling View : 1972 Reply : 12
 

 

No. 1



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



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

ก็ง่าย ๆ ครับ ในปุ่มลิ้งค์ ที่ใช้กดออกรายงานอ่ะครับ แทรกค่าที่ใช้ค้นหามาพร้อมกับลิ้งค์ด้วยอ่ะครับ

<"ชื่อไฟล์ออกรายงาน.php?start_date=ค่าวันที่&end_date=ค่าวันที่">
แล้วจากโค้ดที่ได้จากการค้นหา ให้แก้เป็น
Code (PHP)
<?
header("Content-type: application/vnd.ms-excel");
// header('Content-type: application/csv'); //*** CSV ***//
header("Content-Disposition: attachment; filename=receive_send.xls");
//แก้ส่วนนี้
?>
<html>
<body>
<body>
<? include("f_thaidate.php");?>
<? include("datepick/datepick.php"); ?>
<?
    $strSQL = "SELECT * FROM receive_send WHERE send_date BETWEEN '".$_GET['start_date']."' and '".$_GET['end_date']."'"; 
	$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");

	?>
<table width="1000" border="1">
<tr>
		<th width="85"> <div align="center">เลขที</div></th>
		<th width="80"> <div align="center">ลงวันที่</div></th>
		<th width="95"> <div align="center">จาก</div></th>
		<th width="95"> <div align="center">ถึง </div></th>
		<th width="320"> <div align="center">เรื่อง</div></th>
		<th width="97"> <div align="center">ผู้ส่ง</div></th>
        <th width="110"> <div align="center">สถานะ</div></th>
        <th width="110"> <div align="center">การปฏิงัติ</div></th>
        <th width="40"> <div align="center">แก้ไข</div></th>
        <th width="40"> <div align="center">ลบ</div></th>

  </tr>	<?
while($objResult = mysql_fetch_array($objQuery))
{

?>
	   <tr>
		<td align="center"><?=$objResult["send_no"];?></td>
		<td align="center"><?=$objResult["send_date"];?></td>
		<td align="center"><?=$objResult["receive_send_from"];?></td>
		<td align="center"><?=$objResult["receive_send_to"];?></td>
		<td align="center"><?=$objResult["receive_send_name"];?></td>
		<td align="center"><?=$objResult["receive_send_emp"];?></td>
        <td align="center"><?=$objResult["receive_send_check"];?></td>
        <td align="center"><?=$objResult["receive_send_note"];?></td>
        <td align="center"><a href="Receive_SendEditForm.php?SendNo=<?=$objResult["send_no"];?>"><img src="images/update.png" width="22" height="22" /></a></td>
        <td align="center"><a href="JavaScript:if(confirm('ยืนยันการลบข้อมูล')==true){window.location='ReceiveDelete.php?SendNo=<?=$objResult["send_no"];?>';}"><img src="images/delete.png" width="22" height="22" /></a></td>

	  </tr>
	<?
	}
	?>
	</table>
<?
	
	mysql_close($objConnect);

	}
	
	?>

</body>



อันนี้เป็นแบบที่ผมใช้งานอยู่ อธิบายง่ายๆ เลยคือ เรียกหน้าเดิมซ้ำอีกรอบ แต่เปลี่ยน Header เอาครับ ส่วนวิธีส่งค่าให้กับลิ้งค์ก็ลองศึกษาเพิ่มครับ








ประวัติการแก้ไข
2013-03-14 22:56:27
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-03-14 22:54:55 By : akkaneetha
 


 

No. 2



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

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

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

ตอบความคิดเห็นที่ : 1 เขียนโดย : akkaneetha เมื่อวันที่ 2013-03-14 22:54:55
รายละเอียดของการตอบ ::
... ค่าวันที่มันมาจากการค้นหา ไม่ได้กำหนดขึ้นเอง

ต้องทำยังไงคะ ไปไม่ถูก

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-03-14 23:18:59 By : gosling
 

 

No. 3



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



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

ลองบอกแนวทางละกันนะครับ เพราะโค้ดที่ใช้คล้ายๆกัน
ไฟล์ แสดงข้อมูล.php
เมื่อใส่ค่าวันที่ที่ได้จากการเลือกจากปฏิทิน(ค่าเป็น ปี-เดือน-วัน)
แล้วพอกดค้นหาก็จะทำการค้นหาและแสดงข้อมูลตามช่วงวันที่ที่ระบุ(ถูกต้องใช่มั้ยครับ)
แล้วจากกระบวนการนี้ หน้าเพจจะทำการรีเฟสทุกครั้งเมื่อมีการกดค้นหา เพื่อรับค่าค้นหาใหม่เข้ามา

ดังนั้นในหน้านี้เราก็สร้างลิ้งค์ไว้ตรงไหนสักที่ ที่ไม่เกี่ยวข้องกันตารางแสดงข้อมูล เช่น

ออกรายงาน

--------------------

ตารางแสดงข้อมูล

ในส่วนของลิ้งค์นั้น ก็จะเป็นการอ้างอิงไปที่ไฟล์ ออกรายงาน.php ซึ่งก็ใช้รูปแบบในความเห็นก่อนหน้านี้นะครับ

โดยที่ลิ้งค์ก็ใส่ค่าเพิ่มเติมให้กับลิ้งค์ จากโค้ดอาจใส่เป็น
Code (PHP)
ออกรายงาน.php?start_date=<?=$_GET[start_date]?>&end_date=<?=$_GET[end_date]

หรือ
Code (PHP)
ออกรายงาน.php?start_date=<?=$_REQUEST[start_date]?>&end_date=<?=$_REQUEST[end_date]
//ทำงานเหมือนกับ GET และ POST แต่ REQUEST สามารถรับค่าได้จากทั้ง GET และ POST


ตัวอย่างโค้ดที่เคยทำไว้ ลองปรับใช้ดูนะครับ

ไฟล์ list_PM.php
Code (PHP)
<?
session_start();
	if ($_SESSION['ADMINID'] == "") {    //ถ้าตัวแปรเป็นค่า ว่าง
	header("Location:../index.php");   //ให้ไปหน้า login
 }	
	include("../connect.php");
	$strSQL = "SELECT * FROM members WHERE UserID = '".$_SESSION['ADMINID']."' ";
	$objQuery = mysql_query($strSQL);
	$objResult = mysql_fetch_array($objQuery);
	mysql_query("SET character_set_results=UTF8");
	mysql_query("SET character_set_client=UTF8");
	mysql_query("SET character_set_connection=UTF8");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="../Scripts/epoch_styles.css"/>
<script type="text/javascript" src="../Scripts/epoch_classes.js">//***Calendar****//</script>
<script type="text/javascript">
var calendar;
window.onload = function() {
calendar = new Epoch('cal2','popup',document.getElementById('calendar_container'),false);
calendar = new Epoch('cal2','popup',document.getElementById('calendar_container2'),false);	
};
</script>
<script type="text/javascript">
function MM_openBrWindow(URL, N, W, H, S) { // name, width, height, scrollbars
var winleft    =    (screen.width - W) / 2;
var winup    =    (screen.height - H) / 2;
winProp        =    'width='+W+',height='+H+',left='+winleft+',top=' +winup+',scrollbars='+S+',resizable' + ',status=no'
Win            =    window.open(URL, N, winProp)
}
</script>
<style type="text/css">
.style1 {font-size: 14px;
	font-weight: bold;
}
.style19 {font-size: 13px}
a:link {
	color: #0066FF;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #0066FF;
}
a:hover {
	text-decoration: none;
	color: #00FF00;
}
a:active {
	text-decoration: none;
	color: #0066FF;
}
.style3 {font-size: 12px}
.style5 {
	font-size: 14px;
	font-weight: bold;
	color: #000000;
}
</style>
</head>

<body>
<script language="javascript">
function fncSubmit()
{
	if(document.frmSearch.ddlSelect.value == "select")
	{
		alert('กรุณาเลือกสิ่งที่ต้องการค้นหา');
		document.frmSearch.ddlSelect.focus();
		return false;
	}	
	document.frmSearch.submit();
}
</script>
<table border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#333333">
  <tr>
    <td colspan="7" bgcolor="#FFFFFF">
    <form name="frmSearch" method="post" OnSubmit="return fncSubmit();" action="<?=$_SERVER['SCRIPT_NAME'];?>">
      <strong>
      ค้นหาโดย 
      <label>
      <select name="ddlSelect" id="ddlSelect" style="width:100px">
      <option value="select" selected="selected">- Select -</option>
      <option value="node"<?if($_POST["ddlSelect"]=="node"){echo"selected";}?>>Node</option>
      <option value="dslam"<?if($_POST["ddlSelect"]=="dslam"){echo"selected";}?>>Dslam</option>
      <option value="location"<?if($_POST["ddlSelect"]=="location"){echo"selected";}?>>Location</option>
      <option value="worker"<?if($_POST["ddlSelect"]=="worker1"){echo"selected";}?>>ชื่อผู้ปฏิบัติงาน</option>
      <option value="date_up"<?if($_POST["ddlSelect"]=="date_up"){echo"selected";}?>>วันที่ปฏิบัติงาน</option>
      </select>
      </label>
     สิ่งที่ต้องการค้นหา 
     <label>
     <input type="text" name="txtKeyword" id="calendar_container" value="<?=$_POST["txtKeyword"];?>"/>
     ถึงวันที่ 
     <input name="txtKeyword2" type="text" id="calendar_container2" value="<?=$_POST["txtKeyword2"];?>" />
     <input type="submit" name="serach" id="serach" value="ค้นหา" />
     </label>  
      </strong>
    </form></td>
    <?
$_POST['ddlSelect']=$_REQUEST['ddlSelect'];
$_POST['txtKeyword']=$_REQUEST['txtKeyword'];
$_POST['txtKeyword2']=$_REQUEST['txtKeyword2'];
// Search
	$PMSQL = "SELECT * FROM savepm WHERE 1";
	if ($_POST["ddlSelect"] != "" and  $_POST["txtKeyword"]  != '')
	{
		if($_POST["ddlSelect"] == "worker"){
		$PMSQL .= " AND (worker1 LIKE '%".$_POST["txtKeyword"]."%' or worker2 LIKE '%".$_POST["txtKeyword"]."%')";
		}
			else
			{
				if($_POST["ddlSelect"]=="date_up"){
				$PMSQL .= " AND (date BETWEEN '".$_POST["txtKeyword"]."' AND '".$_POST["txtKeyword2"]."' )";
				}
					else
					{
					$PMSQL .= " AND (".$_POST["ddlSelect"]." LIKE '%".$_POST["txtKeyword"]."%' )";
					}
			 }
		}
	$PMQuery = mysql_query($PMSQL) or die ("Error Query [".$PMSQL."]");
	$Num_Rows = mysql_num_rows($PMQuery); 
	$Per_Page = 50;   // Per Page
	$Page = $_GET["Page"];
	if(!$_GET["Page"])
	{
		$Page=1;
	}
	$Prev_Page = $Page-1;
	$Next_Page = $Page+1;
	$Page_Start = (($Per_Page*$Page)-$Per_Page);
	if($Num_Rows<=$Per_Page)
	{
		$Num_Pages =1;
	}
	else if(($Num_Rows % $Per_Page)==0)
	{
		$Num_Pages =($Num_Rows/$Per_Page) ;
	}
	else
	{
		$Num_Pages =($Num_Rows/$Per_Page)+1;
		$Num_Pages = (int)$Num_Pages;
	}
$strSort = $_GET["sort"];
if($strSort == "")
{
	$strSort = "dslam";
}
$strOrder = $_GET["order"];
if($strOrder == "")
{
	$strOrder = "ASC";
}
$PMSQL .=" order  by ".$strSort." ".$strOrder." LIMIT $Page_Start , $Per_Page";
$PMQuery  = mysql_query($PMSQL);
$strNewOrder = $strOrder == 'DESC' ? 'ASC' : 'DESC';
?>
  </tr>
  <tr>
    <td colspan="7" align="right" bgcolor="#FFFFFF"><a href="javascript:MM_openBrWindow('export_list_PM.php?sort=<?=$strSort?>&order=<?=$strNewOrder?>&ddlSelect=<?=$_POST['ddlSelect']?>&txtKeyword=<?=$_POST['txtKeyword']?>&txtKeyword2=<?=$_POST['txtKeyword2']?>','detail','480','300','no')" class="style20"><img src="../image/brights_lrg_22.gif" width="56" height="57" border="0" /></a></td>
<?
//ตรงนี้เป็นลิ้งค์ที่ผมใช้สำหรับเรียกหาไฟล์ออกรายงานครับ โดยรับค่ามาจากช่อง textbox  
?>
  </tr>
  <tr align="center">
    <td colspan="7" bgcolor="#FFFFFF"><table width="744" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td align="center"><span class="style5">รวม
          &nbsp;&nbsp;&nbsp;
                <?= $Num_Rows;?>
&nbsp;รายการ :
          &nbsp;&nbsp;
                <?=$Num_Pages;?>
            หน้า :&nbsp;
            <?
	if($Prev_Page)
	{
		echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&ddlSelect=".$_POST["ddlSelect"]."&txtKeyword=".$_POST["txtKeyword"]."&txtKeyword2=".$_POST["txtKeyword2"]."&sort=$strSort&order=$strOrder'><< Back</a> ";
	}

	for($i=1; $i<=$Num_Pages; $i++){
		if($i != $Page)
		{
			echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&ddlSelect=".$_POST["ddlSelect"]."&txtKeyword=".$_POST["txtKeyword"]."&txtKeyword2=".$_POST["txtKeyword2"]."&sort=$strSort&order=$strOrder'>$i</a> ]";
		}
		else
		{
			echo "<b> $i </b>";
		}
	}
	if($Page!=$Num_Pages)
	{
		echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&ddlSelect=".$_POST["ddlSelect"]."&txtKeyword=".$_POST["txtKeyword"]."&txtKeyword2=".$_POST["txtKeyword2"]."&sort=$strSort&order=$strOrder'>Next>></a> ";
		}
?>
        </span></td>
      </tr>
    </table></td>
  </tr>
  <tr align="center">
    <td width="100" bgcolor="#FFFFFF"><a href="<?=$_SERVER["SCRIPT_NAME"];?>?sort=node&order=<?=$strNewOrder?>&ddlSelect=<?=$_POST['ddlSelect']?>&txtKeyword=<?=$_POST['txtKeyword']?>&txtKeyword2=<?=$_POST['txtKeyword2']?>" class="style23 style3"><strong>Node</strong></a></td>
    <td width="121" bgcolor="#FFFFFF"><a href="<?=$_SERVER["SCRIPT_NAME"];?>?sort=dslam&order=<?=$strNewOrder?>&ddlSelect=<?=$_POST['ddlSelect']?>&txtKeyword=<?=$_POST['txtKeyword']?>&txtKeyword2=<?=$_POST['txtKeyword2']?>" class="style23 style3"><strong>Dslam</strong></a></td>
    <td width="168" bgcolor="#FFFFFF"><a href="<?=$_SERVER["SCRIPT_NAME"];?>?sort=location&order=<?=$strNewOrder?>&ddlSelect=<?=$_POST['ddlSelect']?>&txtKeyword=<?=$_POST['txtKeyword']?>&txtKeyword2=<?=$_POST['txtKeyword2']?>" class="style23 style3"><strong>Location</strong></a></td>
    <td width="120" bgcolor="#FFFFFF"><a href="<?=$_SERVER["SCRIPT_NAME"];?>?sort=worker1&order=<?=$strNewOrder?>&ddlSelect=<?=$_POST['ddlSelect']?>&txtKeyword=<?=$_POST['txtKeyword']?>&txtKeyword2=<?=$_POST['txtKeyword2']?>" class="style23 style3"><strong>ผู้ปฏิบัติงาน</strong></a></td>
    <td width="120" bgcolor="#FFFFFF"><a href="<?=$_SERVER["SCRIPT_NAME"];?>?sort=worker2&order=<?=$strNewOrder?>&ddlSelect=<?=$_POST['ddlSelect']?>&txtKeyword=<?=$_POST['txtKeyword']?>&txtKeyword2=<?=$_POST['txtKeyword2']?>" class="style23 style3"><strong>ผู้ปฏิบัติงาน</strong></a></td>
    <td width="100" bgcolor="#FFFFFF"><a href="<?=$_SERVER["SCRIPT_NAME"];?>?sort=date_up&order=<?=$strNewOrder?>&ddlSelect=<?=$_POST['ddlSelect']?>&txtKeyword=<?=$_POST['txtKeyword']?>&txtKeyword2=<?=$_POST['txtKeyword2']?>" class="style23 style3"><strong>วันที่ปฏิบัติงาน</strong></a></td>
    <td width="100" bgcolor="#FFFFFF">&nbsp;</td>
  </tr>
<?
while($PMResult = mysql_fetch_array($PMQuery))
{
$i++;
if($i%2==0){$bg = "#FFFFCC";}// ใส่สีในตารางแบบสลับสี ตั้งแต่ $i ถึง $bg
else{$bg = "#FFFFFF";}
?>
  <tr bgcolor="<?=$bg;?>">
    <td align="center"><span class="style19">
      <?=$PMResult["node"];?>
    </span></td>
    <td align="center"><span class="style19">
      <?=$PMResult["dslam"];?>
    </span></td>
    <td><span class="style19">
      <?=$PMResult["location"];?>
    </span></td>
    <td><span class="style19">
      <?=$PMResult["worker1"];?>
    </span></td>
    <td><span class="style19">
      <?=$PMResult["worker2"];?>
    </span></td>
    <td><span class="style19">
      <?=$PMResult["date_up"];?>
    </span></td>
    <td><span class="style3"><strong><a href="javascript:MM_openBrWindow('show_listPM.php?location=<?=$PMResult["node_H"];?>','detail','780','500','yes')" class="style20">รายละเอียด</a></strong></span></td>
  </tr>
  <?
}
?>
</table>
<p>&nbsp;</p>
<table width="744" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center"><span class="style1"><strong>รวม
      &nbsp;&nbsp;&nbsp;
                <?= $Num_Rows;?>
      &nbsp;รายการ :
      &nbsp;&nbsp;
                <?=$Num_Pages;?>
      หน้า :&nbsp;
      <?
	if($Prev_Page)
	{
		echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&ddlSelect=".$_POST["ddlSelect"]."&txtKeyword=".$_POST["txtKeyword"]."&txtKeyword2=".$_POST["txtKeyword2"]."&sort=$strSort&order=$strOrder'><< Back</a> ";
	}

	for($i=1; $i<=$Num_Pages; $i++){
		if($i != $Page)
		{
			echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&ddlSelect=".$_POST["ddlSelect"]."&txtKeyword=".$_POST["txtKeyword"]."&txtKeyword2=".$_POST["txtKeyword2"]."&sort=$strSort&order=$strOrder'>$i</a> ]";
		}
		else
		{
			echo "<b> $i </b>";
		}
	}
	if($Page!=$Num_Pages)
	{
		echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&ddlSelect=".$_POST["ddlSelect"]."&txtKeyword=".$_POST["txtKeyword"]."&txtKeyword2=".$_POST["txtKeyword2"]."&sort=$strSort&order=$strOrder'>Next>></a> ";
		}
?>
    </strong></span></td>
  </tr>
</table>
</body>
</html>


ไฟล์ export_list_PM.php
Code (PHP)
<?
header("Content-type: application/vnd.ms-excel");
// header('Content-type: application/csv'); //*** CSV ***//
header("Content-Disposition: attachment; filename=List_PM_Inc.xls");
?>
<html>
<head>
<title>: : Report Data : :</title>
</head>
<table border="1" align="center">
  <tr align="center">
    <td width="100" bgcolor="#FFFFFF"><strong>Node</strong></td>
    <td width="121" bgcolor="#FFFFFF"><strong>Dslam</strong></td>
    <td width="168" bgcolor="#FFFFFF"><strong>Location</strong></td>
    <td width="120" bgcolor="#FFFFFF"><strong>ผู้ปฏิบัติงาน</strong></td>
    <td width="120" bgcolor="#FFFFFF"><strong>ผู้ปฏิบัติงาน</strong></td>
    <td width="100" bgcolor="#FFFFFF"><strong>วันที่ปฏิบัติงาน</strong></td>
  </tr>
  <?
$sort=$_REQUEST['sort'];
$order2=$_REQUEST['order'];
if($order2 == 'DESC'){
$order = 'ASC';}
else{
$order= 'DESC';}
$ddlSelect=$_REQUEST['ddlSelect'];
$txtKeyword=$_REQUEST['txtKeyword'];
$txtKeyword2=$_REQUEST['txtKeyword2'];
include("../connect.php");
	$PMSQL = "SELECT * FROM savepm WHERE 1";
	if($ddlSelect !="" and $txtKeyword !="")
	{
		if($ddlSelect =='worker'){
		$PMSQL .= " AND (worker1 LIKE '%$txtKeyword%' or worker2 LIKE '%$txtKeyword%')";
		}
			else
			{
				if($ddlSelect =='date_up'){
				$PMSQL .= " AND (date_up BETWEEN '$txtKeyword' AND '$txtKeyword2' )";
				}
					else
					{
					$PMSQL .= " AND ( $ddlSelect LIKE '%$txtKeyword%' )";
					}
			 }
		}
	$PMSQL .=" ORDER BY $sort $order";
	$PMQuery = mysql_query($PMSQL) or die ("Error Query [".$PMSQL."]");
	while($PMResult = mysql_fetch_array($PMQuery))
	{
	?>
  <tr>
    <td align="center"><span class="style19">
      <?=$PMResult["node"];?>
    </span></td>
    <td align="center"><span class="style19">
      <?=$PMResult["dslam"];?>
    </span></td>
    <td><span class="style19">
      <?=$PMResult["location"];?>
    </span></td>
    <td><span class="style19">
      <?=$PMResult["worker1"];?>
    </span></td>
    <td><span class="style19">
      <?=$PMResult["worker2"];?>
    </span></td>
    <td><span class="style19">
      <?=$PMResult["date_up"];?>
    </span></td>
  </tr>
  <?
}
?>
</table>




ลองศึกษาเปรียบเทียบดูครับ ใช้โค้ดคล้าย ๆ กัน น่าจะพอช่วยได้
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-03-14 23:55:12 By : akkaneetha
 


 

No. 4



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

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

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

ตอบความคิดเห็นที่ : 3 เขียนโดย : akkaneetha เมื่อวันที่ 2013-03-14 23:55:12
รายละเอียดของการตอบ ::
... ยังทำไม่ได้เลยค่ะ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-03-15 00:38:20 By : gosling
 


 

No. 5



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



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

ถึงกับต้องมีจดหมายตามมาตอบเลยทีเดียว งั้นเดี๋ยวขอลองมั่วสักแปปครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-03-15 01:26:49 By : jackkichan
 


 

No. 6



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

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

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

ตอบความคิดเห็นที่ : 5 เขียนโดย : jackkichan เมื่อวันที่ 2013-03-15 01:26:49
รายละเอียดของการตอบ ::
...ไปไม่ถูกแล้วค่ะ T_T

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-03-15 01:31:20 By : gosling
 


 

No. 7



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



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

อ่อลืมถามครับ แล้วตัวเดิมที่ เอาออกมาทั้งหมดนี้มันได้หรือเปล่าครับ หรือว่าไม่ได้เฉพาะตอนค้นหา
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-03-15 01:43:13 By : jackkichan
 


 

No. 8



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

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

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

ตอบความคิดเห็นที่ : 7 เขียนโดย : jackkichan เมื่อวันที่ 2013-03-15 01:43:13
รายละเอียดของการตอบ ::
... ได้ค่ะ ข้อมูลออกมาหมดทั้งตารางค่ะ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-03-15 01:44:12 By : gosling
 


 

No. 9



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



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

โอเค เสร็จละครับ

เพิ่ม ลิงค์นี้เข้าไปที่ไหนก็ได้ ใต้ตารางก็ได้
<a href="export_excel.php?st=<?=$_GET['start_date']?>&&en=<?=$_GET['end_date']?>">ส่งออกข้อมูล</a>

จากนั้นสร้างไฟล์ใหม่ขึ้นมาน่ะครับ สำหรับการ export

ไฟล์ export_excel.php
<? 
	$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
	$objDB = mysql_select_db("book");
	mysql_query("SET NAMES UTF8");
    $strSQL = "SELECT * FROM receive_send WHERE send_date BETWEEN '".$_GET['st']."%' and '".$_GET['en']."%'"; 
	$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
	header("Content-Type: application/vnd.ms-excel");
	header('Content-Disposition: attachment; filename="Myexport.xls"');
	
 ?>
<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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ส่งออกรายงาน</title>
</head>

<body>

<table width="1000" border="1">
<tr>
		<th width="85"> <div align="center">เลขที</div></th>
		<th width="80"> <div align="center">ลงวันที่</div></th>
		<th width="95"> <div align="center">จาก</div></th>
		<th width="95"> <div align="center">ถึง </div></th>
		<th width="320"> <div align="center">เรื่อง</div></th>
		<th width="97"> <div align="center">ผู้ส่ง</div></th>
        <th width="110"> <div align="center">สถานะ</div></th>
        <th width="110"> <div align="center">การปฏิงัติ</div></th>


  </tr>	<?
while($objResult = mysql_fetch_array($objQuery))
{

?>
	   <tr>
		<td align="center"><?=$objResult["send_no"];?></td>
		<td align="center"><?=$objResult["send_date"];?></td>
		<td align="center"><?=$objResult["receive_send_from"];?></td>
		<td align="center"><?=$objResult["receive_send_to"];?></td>
		<td align="center"><?=$objResult["receive_send_name"];?></td>
		<td align="center"><?=$objResult["receive_send_emp"];?></td>
        <td align="center"><?=$objResult["receive_send_check"];?></td>
        <td align="center"><?=$objResult["receive_send_note"];?></td>
	  </tr>
	<?
	}
	?>
	</table>



</body>
</html>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-03-15 02:09:29 By : jackkichan
 


 

No. 10



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

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

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

น่าจะประมาณนี้ครับ
<?
header("Content-type: application/vnd.ms-excel");
// header('Content-type: application/csv'); //*** CSV ***//
header("Content-Disposition: attachment; filename=receive_send.xls");
?>
<html>
<body>

<?
	$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
	$objDB = mysql_select_db("book");
	mysql_query("SET NAMES UTF8");
	// ******** ตรงนี้ครับ *******
	// หากมีการกำหนดวันค้นหา ทั้งวันเริ่ม และวันจบ
	if (!empty($_POST['start_date']) && !empty($_POST['end_date'])) {
		// เลือกเฉพาะวันที่ที่อยู่ระหว่างวันเริ่ม และวันสิ้นสุด
		$strSQL = "
		SELECT *
		FROM receive_send
		WHERE `send_date`
			BETWEEN '$_POST[start_date]'
			AND '$_POST[end_date]'";
	}
	// หากมีการกำหนดวันค้นหา แค่วันเริ่ม
	elseif (!empty($_POST['start_date'])) {
		// เลือกเฉพาะวันที่ที่มากกว่าหรือเท่ากับวันสิ้นสุด
		$strSQL = "
		SELECT *
		FROM receive_send
		WHERE `send_date` >= '$_POST[start_date]'";
	}
	// หากมีการกำหนดวันค้นหา แค่วันสิ้นสุด
	elseif (!empty($_POST['end_date'])) {
		// เลือกเฉพาะวันที่ที่น้อยกว่าหรือเท่ากับวันสิ้นสุด
		$strSQL = "
		SELECT *
		FROM receive_send
		WHERE `end_date` <= '$_POST[end_date]'";
	}
	// นอกนั้นแสดงทั้งหมดอย่างไม่มีเงื่อนไข
	else {
		$strSQL = "
		SELECT *
		FROM receive_send";
	}
	$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="1000" border="0" align="center">
  <tr>
    <td align="center">หนังสือรับ - ส่งทั้งหมด</td>
  </tr>
  <tr>
    <td align="center">หน่วยงานกองช่าง</td>
  </tr>
</table>

<table width="1000" border="1" align="center">
<tr>
		<th width="120"> <div align="center">เลขที่หนังสือส่ง</div></th>
		<th width="106"> <div align="center">ลงวันที่</div></th>
        <th width="106"> <div align="center">วันที่รับ</div></th>
		<th width="138"> <div align="center">จาก</div></th>
		<th width="138"> <div align="center">ถึง </div></th>
		<th width="234"> <div align="center">เรื่อง</div></th>
		<th width="156"> <div align="center">ผู้รับ</div></th>
		<th width="156"> <div align="center">สถานะ</div></th>
        <th width="106"> <div align="center">การปฏิบัติ</div></th>

  </tr>
<?
	while($objResult = mysql_fetch_array($objQuery))
	{
?>
	<tr>
    <td height="30" align="center"><?=$objResult["send_no"];?></td>
    <td align="center"><?=$objResult["send_date"];?></td>
    <td align="center"><?=$objResult["receive_date"];?></td>
    <td align="center"><?=$objResult["receive_send_from"];?></td>
    <td align="center"><?=$objResult["receive_send_to"];?></td>
    <td align="center"><?=$objResult["receive_send_name"];?></td>
    <td align="center"><?=$objResult["receive_send_emp"];?></td>
    <td align="center"><?=$objResult["receive_send_check"];?></td>
    <td align="center"><?=$objResult["receive_send_note"];?></td>
    </tr>
<?
}
?>
</table>
<?
	mysql_close($objConnect);
?>
</body>
</html>


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-03-15 02:15:16 By : cookiephp
 


 

No. 11



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

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

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

ได้แล้วค่ะ ขอบคุณพี่ฟูฟู และก็พี่แมวด้วยค่ะ ที่ช่วยแก้ไขโค้ดให้

เมื่อวานไปส่งระบบให้อาจารย์ดูแล้วค่ะ เสร็จหมดแล้ว แต่ให้เพิ่มตรงส่วนนี้ค่ะ

พรุ่งนี้ได้ไปส่งแล้ว


ขอบคุณพี่ๆมากๆเลยค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-03-15 02:37:07 By : gosling
 


 

No. 12



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

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

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

ตอบความคิดเห็นที่ : 11 เขียนโดย : gosling เมื่อวันที่ 2013-03-15 02:37:07
รายละเอียดของการตอบ ::


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-03-15 03:09:27 By : cookiephp
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถามเรื่อง การออกรายงานเป็น 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 00
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 อัตราราคา คลิกที่นี่