 |
รบกวนอีกนะค่ะ เขียนไม่ค่อยเก่ง ที่เก่งก็คือความพยายาม....อย่างเดียว รายงานยอดขายสินค้าแยกประเภทตามช่วงเวลาที่กำหนด |
|
 |
|
|
 |
 |
|

รายงานยอดขายสินค้าแยกประเภทตามช่วงเวลาที่กำหนด หน้านี้เป็นฟอร์มให้เลือกวันที่ ว่าจะเอายอดขายตั้งแต่วันที่เท่าไหร่ถึงวันที่เท่าไหร่ พอกดปุ่ม submit จะเรียกฟังค์ชั่น ที่ชื่อ checkdate มาทำงาน
Code (PHP)
<!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>
</head>
<body>
<form method=post action="checkdate.php">
<p>กรุณาเลือกช่วงเวลาค่ะ</p>
<p> ตั้งแต่วันที่
<select name="day">
<option value="">วันที่</option>
<?
for ($i=1;$i<=31;$i++) {
echo "<option value='$i'>$i</option>";
}
?>
</select>
<select name="month">
<option value="">เดือน</option>
<?
$thai_m=array("","มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
for ($i=1;$i<=12;$i++) {
echo "<option value='$i'>$thai_m[$i]</option>";
}
?>
</select>
<select name="year">
<option value="">ปี</option>
<?
for ($i=2012;$i<=2042;$i++) {
$y=$i+543;
echo "<option value='$i'>$i</option>";
}
?>
</select>
จนถึงวันที่ <select name="day2">
<option value="">วันที่</option>
<?
for ($i=1;$i<=31;$i++) {
echo "<option value='$i'>$i</option>";
}
?>
</select>
<select name="month2">
<option value="">เดือน</option>
<?
$thai_m=array("","มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
for ($i=1;$i<=12;$i++) {
echo "<option value='$i'>$thai_m[$i]</option>";
}
?>
</select>
<select name="year2">
<option value="">ปี</option>
<?
for ($i=2012;$i<=2042;$i++) {
$y=$i+543;
echo "<option value='$i'>$i</option>";
}
?>
</select>
<p>
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</form>
</body>
</html>
จะลิงค์ไปอีกหน้านะค่ะหน้านี้ไม่มีรูปค่ะ มีแต่โค้ดอย่างเดียว
Code (PHP)
<?
$day=$_POST[day];
$month=$_POST[month];
$year=$_POST[year];
$day2=$_POST[day2];
$month2=$_POST[month2];
$year2=$_POST[year2];
if($day=="" or $month=="" or $year=="" or $day2=="" or $month2=="" or $year2==""){
echo "<script>alert('กรุณากรอกข้อมูลให้ครบถ้วนด้วนค่ะ')</script>";
exit();
}
if (!checkdate($month,$day,$year)) {
echo "<script>alert('วันที่คุณเลือก ไม่มีอยู่ปฏิทิน')</script>";
exit();
}
if(!checkdate($month2,$day2,$year2)) {
echo "<script>alert('วันที่คุณเลือก ไม่มีอยู่ปฏิทิน')</script>";
exit();
}
//$strat_date="$year and $month and $day";
//$end_date="$year2 and $month2 and $day2";
//echo "$strat_date too $end_date";
include "config.php";
$sql="select type_name,date_order,sum(price*number)
from type,product,tb_order,order_detail
where(id_order.tb_order=ref_id_order.order_detail)
and(ref_id_prd.order_detail=id_prd.product)
and(Type_ID.type=ref_id_type.product)
and(date_order between ($month,$day,$year) and ($month2,$day2,$year2))
group by Type_Name ASC,date_order Desc";
$result=mysql_db_query($dbname,$sql);
$number=mysql_num_rows($result);
$no=1;
?>
<!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>
</head>
<body>
<?
if ($number<>0) {
echo "
<p> </p>
<p> </p>
<table border=1>
<tr bgcolor =#E8E8E8>
<td><center><b>ประเภทสินค้า</b></center></td>
<td><center><b>วันที่ขาย</b></center></td>
<td><center><b>ยอดขาย</b></center></td>
</tr>";
while ($rs=mysql_fetch_array($result)) {
$Type_Name=$rs[Type_Name];
$date_order=$rs[date_order];
$sum=$rs[sum];
echo "
<tr>
<td>$Type_Name</td>
<td>$date_order</td>
<td><center>$sum</center></td>
</tr>
<tr>";
$no++;
}
echo "</table>";
mysql_close();
}
?>
</body>
</html>
ที่โค้ดนี้จะรับค่าจาก sale_report แล้วตรวจว่า วันที่ที่รับมามีอยู่จริงในปฎิทินหรือไม่ ถ้ามี มันก็จะเอาไปเรียก ชื่อประเภทสินค้า วันที่ขาย และ ยอดเงิน join ผ่าน ตาราง type,product,tb_order,order_detail (error : Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\Oilshop\checkdate.php on line 33)
Tag : PHP, MySQL
|
|
 |
 |
 |
 |
Date :
2012-02-29 23:43:50 |
By :
katay |
View :
3240 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตาราง type

ตาราง product

ตาราง tb_order

ตาราง order_detail

ใช้ดูประกอบนะค่ะ... ขอบคุณมากๆๆค่ะ
|
 |
 |
 |
 |
Date :
2012-03-01 00:01:43 |
By :
katay |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยตอบให้หน่อยนะค่ะ มีสอบวันศุกร์เช้าแล้ว....
|
 |
 |
 |
 |
Date :
2012-03-01 11:28:39 |
By :
katay |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$result=mysql_db_query($dbname,$sql) or die(mysql_error() . '<br/>' . $sql);
ใส่นี่เข้าไปครับ จะได้รู้ว่า error อะไรยังไง
|
 |
 |
 |
 |
Date :
2012-03-01 11:52:12 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|