<form name="frmSearch" method="get" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
<font size="-1"> วันที่ : </font> <input name="txtKeyword" type="date" id="txtKeyword"/> <font size="-1"> ถึงวันที่ :</font> <input name="txtKeyword2" type="date" id="txtKeyword2"/>
<input type="submit" value="เลือก" class="box">
</form>
<p></p>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
$objConnect = mysql_connect("localhost","root","admin1234") or die("Error Connect to Database");
$objDB = mysql_select_db("itbookonline");
$a1 = isset($_GET['txtKeyword']) ? $_GET['txtKeyword'] : '';
$a2 = isset($_GET['txtKeyword2']) ? $_GET['txtKeyword2'] : '';
$strAction = $a1 AND $a2;
if($strAction != "")
{
$strSQL = "SELECT *
FROM tbl_order AS o
INNER JOIN
tbl_order_item AS oi
ON (o.od_id = oi.od_id)
INNER JOIN
tbl_product AS p
ON (oi.pd_id = p.pd_id)
WHERE o.od_date BETWEEN $a1 AND $a2"; (ถ้าเป็นเป็น od_id หรือ อื่นๆค้นหาได้หมด)
}
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$total = 0;
$totalqty = 0;
?>
<table width="100%" height="40" border="0" align="center" cellpadding="2" cellspacing="1" class="text">
<tr align="center" id="listTableHeader">
<td width="101" align="center">วันที่และเวลา</td>
<td width="41" align="center">ใบสั่งซื้อ</td>
<td width="41" align="center">รหัสสินค้า</td>
<td width="120" align="center">รายการ</td>
<td width="40" align="center">จำนวน (ชิ้น)</td>
<td width="50" align="center">ราคารวม (บาท)</td>
</tr>
</table>
<?php
while($objResult = mysql_fetch_array($objQuery))
{
$od_date = $objResult["od_date"];
$od_status = $objResult["od_status"];
$od_id = $objResult["od_id"];
$pd_id = $objResult["pd_id"];
$pd_name = $objResult["pd_name"];
$od_qty = $objResult["od_qty"];
$pd_price = $objResult["pd_price"];
if($od_status=="ชำระเงินแล้ว" or $od_status=="จัดส่งแล้ว")
{
for ($a = 0; $a<count($od_id); $a++) {
$sum = $od_qty * $pd_price ;
$total = $total + $sum;
$totalqty = $totalqty + $od_qty;
}
if ($i%2) {
$class = 'row1';
} else {
$class = 'row2';
}
$i += 1;
?>
<table width="100%" height="40" align="center" cellpadding="2" cellspacing="1" class="text">
<tr class="<?php echo $class; ?>">
<td width="100" align="center"><?php echo $od_date;?></td>
<td width="40" align="center"><?php echo $od_id;?></td>
<td width="40" align="center"><?php echo $pd_id;?></td>
<td width="118" align="center"><?php echo $pd_name;?></td>
<td width="43" align="center"><?php echo $od_qty;?></td>
<td width="49" align="right"><?php echo number_format( $od_qty * $pd_price);?></td>
</tr>
</table>
<?php
}
}
?>
<table width="100%" height="80" align="center" cellpadding="2" cellspacing="1" class="text">
<tr class="<?php echo $class; ?>">
<td width="280" align="right">จำนวนสินค้ารวมทั้งสิ้น (ชิ้น) </td>
<td width="37" align="right"><?php echo $totalqty;?></td>
</tr>
<tr class="<?php echo $class; ?>">
<td width="280" align="right">เป็นเงินทั้งสิ้น (บาท) </td>
<td width="37" align="right"><?php echo number_format($total);?></td>
</tr>
</table>
ช่วยแก้Codeหน่อยคับค้นหาระหว่างวันที่ถึงวันที่ไม่แสดงข้อมูลแต่ถ้าค้นเปลี่ยนจาก od_date เป็น od_id หรืออื่นๆค้นหาได้
<font size="-1"> วันที่ : </font> <input name="txtKeyword" type="date" id="txtKeyword"/> <font size="-1"> ถึงวันที่ :</font> <input name="txtKeyword2" type="date" id="txtKeyword2"/>
<input type="submit" value="เลือก" class="box">
</form>
<p></p>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
$objConnect = mysql_connect("localhost","root","admin1234") or die("Error Connect to Database");
$objDB = mysql_select_db("itbookonline");
$a1 = isset($_GET['txtKeyword']) ? $_GET['txtKeyword'] : '';
$a2 = isset($_GET['txtKeyword2']) ? $_GET['txtKeyword2'] : '';
$strAction = $a1 AND $a2;
if($strAction != "")
{
$strSQL = "SELECT *
FROM tbl_order AS o
INNER JOIN
tbl_order_item AS oi
ON (o.od_id = oi.od_id)
INNER JOIN
tbl_product AS p
ON (oi.pd_id = p.pd_id)
WHERE o.od_date BETWEEN $a1 AND $a2"; (ถ้าเป็นเป็น od_id หรือ อื่นๆค้นหาได้หมด)
}
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$total = 0;
$totalqty = 0;
?>
<table width="100%" height="40" border="0" align="center" cellpadding="2" cellspacing="1" class="text">
<tr align="center" id="listTableHeader">
<td width="101" align="center">วันที่และเวลา</td>
<td width="41" align="center">ใบสั่งซื้อ</td>
<td width="41" align="center">รหัสสินค้า</td>
<td width="120" align="center">รายการ</td>
<td width="40" align="center">จำนวน (ชิ้น)</td>
<td width="50" align="center">ราคารวม (บาท)</td>
</tr>
</table>
<?php
while($objResult = mysql_fetch_array($objQuery))
{
$od_date = $objResult["od_date"];
$od_status = $objResult["od_status"];
$od_id = $objResult["od_id"];
$pd_id = $objResult["pd_id"];
$pd_name = $objResult["pd_name"];
$od_qty = $objResult["od_qty"];
$pd_price = $objResult["pd_price"];
if($od_status=="ชำระเงินแล้ว" or $od_status=="จัดส่งแล้ว")
{
for ($a = 0; $a<count($od_id); $a++) {
$sum = $od_qty * $pd_price ;
$total = $total + $sum;
$totalqty = $totalqty + $od_qty;
}
if ($i%2) {
$class = 'row1';
} else {
$class = 'row2';
}
$i += 1;
?>
<table width="100%" height="40" align="center" cellpadding="2" cellspacing="1" class="text">
<tr class="<?php echo $class; ?>">
<td width="100" align="center"><?php echo $od_date;?></td>
<td width="40" align="center"><?php echo $od_id;?></td>
<td width="40" align="center"><?php echo $pd_id;?></td>
<td width="118" align="center"><?php echo $pd_name;?></td>
<td width="43" align="center"><?php echo $od_qty;?></td>
<td width="49" align="right"><?php echo number_format( $od_qty * $pd_price);?></td>
</tr>
</table>
<?php
}
}
?>
<table width="100%" height="80" align="center" cellpadding="2" cellspacing="1" class="text">
<tr class="<?php echo $class; ?>">
<td width="280" align="right">จำนวนสินค้ารวมทั้งสิ้น (ชิ้น) </td>
<td width="37" align="right"><?php echo $totalqty;?></td>
</tr>
<tr class="<?php echo $class; ?>">
<td width="280" align="right">เป็นเงินทั้งสิ้น (บาท) </td>
<td width="37" align="right"><?php echo number_format($total);?></td>
</tr>
</table>