001.
<?php
002.
$hostname
=
"localhost"
;
003.
$username
=
"root"
;
004.
$password
=
""
;
005.
$dbname
=
"Mobile_db"
;
006.
mysql_connect(
$hostname
,
$username
,
$password
)
or
die
(
"ไม่สามารถติดต่อ server ได้!!"
);
007.
mysql_select_db(
$dbname
)
or
die
(
"ไม่สามารถติดต่อฐานข้อมูลได้"
);
008.
009.
require_once
(
"../include/headeradminmenu.php"
);
010.
require_once
(
"../include/shopping_function.php"
);
011.
012.
?>
013.
014.
<table bgcolor=
"#FFCCCC"
border=
"0"
width=
"50%"
style=
"font-weight:bold; color:#666666"
>
015.
<tr bgcolor=
"#FFFFCC"
height=
"30"
align=
"center"
>
016.
<form action=
"admin_reporttest.php"
method=
"post"
>
017.
<td colspan=
"6"
align=
"right"
>ค้นหา :
018.
<?php
$month
=
array
(
"มกราคม"
,
"กุมพาพันธ์"
,
"มีนาคม"
,
"เมษายน"
,
"พฤษภาคม"
,
"มิถุนายน"
,
"กรกฎาคม"
,
"สิงหาคม"
,
"กันยายน"
,
"ตุลาคม"
,
"พฤษจิกายน"
,
"ธันวาคม"
) ;
019.
echo
'<select name="selMonth">'
;
020.
for
(
$i
= 0;
$i
<
count
(
$month
) ;
$i
++ ) {
021.
$mValue
=
$i
+ 1 ;
022.
if
( !
empty
(
$_POST
[
"selMonth"
]) &&
$mValue
==
$_POST
[
"selMonth"
] ) {
023.
$mSelect
=
'selected="selected"'
;
024.
$thai_month
=
$month
[
$i
] ;
025.
}
elseif
(
empty
(
$_POST
[
"selMonth"
]) &&
$mValue
==
date
(
"n"
) ) {
026.
$mSelect
=
'selected="selected"'
;
027.
$thai_month
=
$month
[
$i
] ;
028.
}
else
{
029.
unset(
$mSelect
);
030.
}
031.
echo
'<option value="'
.
$mValue
.
'" '
.
$mSelect
.
'>'
.
$month
[
$i
].
'</option>'
;
032.
}
033.
echo
' </select>'
;
034.
035.
echo
'<select name="selYear">'
;
036.
$startYear
= 2550 ;
037.
$currYear
=
date
(
"Y"
) + 543 ;
038.
for
(
$i
=
$currYear
;
$i
>=
$startYear
;
$i
-- ) {
039.
$yValue
=
$i
- 543 ;
040.
if
( !
empty
(
$_POST
[
"selYear"
]) &&
$yValue
==
$_POST
[
"selYear"
] ) {
041.
$ySelect
=
'selected="selected"'
;
042.
$thai_year
=
$_POST
[
"selYear"
] + 543 ;
043.
}
elseif
(
empty
(
$_POST
[
"selYear"
]) &&
$yValue
==
date
(
"Y"
) ) {
044.
$ySelect
=
'selected="selected"'
;
045.
$thai_year
=
date
(
"Y"
) + 543 ;
046.
}
else
{
047.
unset(
$ySelect
) ;
048.
}
049.
echo
'<option value="'
.
$yValue
.
'" '
.
$ySelect
.
'>'
.
$i
.
'</option>'
;
050.
}
051.
echo
'</select>'
;
052.
echo
'<input type="submit" value="ตกลง" name="OK" />'
; ?></td>
053.
</form>
054.
</tr>
055.
<tr bgcolor=
"#FFFFCC"
height=
"30"
align=
"center"
><td colspan=
"6"
>
056.
<?php
echo
" รายงานสรุปยอดขาย"
.
$thai_month
.
" "
.
$thai_year
; ?>
057.
</td></tr>
058.
<tr bgcolor=
"#999999"
height=
"30"
style=
"color:#FFFFFF;"
align=
"center"
><td colspan=
"6"
>
059.
รายงานสรุปยอดขาย
060.
</td></tr>
061.
<tr bgcolor=
"#A2374D"
height=
"30"
style=
"color:#FFFFFF;"
align=
"center"
>
062.
<td border=
"0"
width=
"20%"
>รหัสสินค้า</td>
063.
<td border=
"0"
width=
"20%"
>ชื่อสินค้า</td>
064.
<td border=
"0"
width=
"20%"
>จำนวน</td>
065.
</tr>
066.
067.
<?php
if
( !
empty
(
$_POST
[
"selYear"
]) || !
empty
(
$_POST
[
"selMonth"
]) ){
068.
$beginDate
=
$_POST
[
"selYear"
].
"-"
.
$_POST
[
"selMonth"
].
"-1"
;
069.
$endDate
=
$_POST
[
"selYear"
].
"-"
.
$_POST
[
"selMonth"
].
"-31"
;
070.
}
else
{
071.
$beginDate
=
date
(
"m-Y"
).
"-1"
;
072.
$endDate
=
date
(
"m-Y"
).
"-31"
;
073.
074.
}
075.
076.
$sqlOrder
=
'SELECT product_id, product_name, count(*) as product_all , sum(quantity) as sum_quantity FROM Order_Items WHERE order_items.orderID = orderID AND (Date BETWEEN "'
.
$beginDate
.
'" AND "'
.
$endDate
.
'" ) GROUP BY product_id ORDER BY sum_quantity ASC '
;
077.
$dbquery
= mysql_db_query(
$dbname
,
$sqlOrder
);
078.
$numOrder
= mysql_num_rows(
$dbquery
);
079.
if
(
$numOrder
== 0 ) {
080.
echo
'<tr bgcolor="#FFFFCC" align="center"><td colspan="6">ไม่มีรายการที่ค้นหา</td></tr>'
;
081.
}
082.
else
083.
$i
=1;
084.
while
(
$i
<=
$numOrder
)
085.
{
086.
087.
$result
= mysql_fetch_array(
$dbquery
);
088.
$product_id
=
$result
[product_id];
089.
$product_name
=
$result
[product_name];
090.
$sum_quantity
=
$result
[sum_quantity];
091.
092.
093.
094.
echo
"<tr><td><CENTER>$product_id</CENTER></td><td><CENTER>$product_name</CENTER><td><CENTER>$sum_quantity</CENTER></td></td></tr>"
;
095.
096.
097.
$i
++;
098.
}
099.
echo
'</table>'
;
100.
?>
101.
..............................................................................................................................................................................................
102.
ไฟล์ shopping_function.php
103.
104.
<?php
105.
function
get_datethai(
$strDate
,
$mode
=
"digit"
,
$type
=
"date"
) {
106.
$month_key
=
array
(
"01"
,
"02"
,
"03"
,
"04"
,
"05"
,
"06"
,
"07"
,
"08"
,
"09"
,
"10"
,
"11"
,
"12"
) ;
107.
$month_full
=
array
(
"มกราคม"
,
"กุมพาพันธ์"
,
"มีนาคม"
,
"เมษายน"
,
"พฤษภาคม"
,
"มิถุนายน"
,
"กรกฎาคม"
,
"สิงหาคม"
,
"กันยายน"
,
"ตุลาคม"
,
"พฤษจิกายน"
,
"ธันวาคม"
) ;
108.
$month_short
=
array
(
"ม.ค."
,
"ก.พ."
,
"มี.ค."
,
"เม.ย."
,
"พ.ค."
,
"มิ.ย"
,
"ก.ค."
,
"ส.ค."
,
"ก.ย."
,
"ต.ค."
,
"พ.ย."
,
"ธ.ค."
) ;
109.
110.
$dDay
=
substr
(
$strDate
, 8, 2 ) ;
111.
$dMonth
=
substr
(
$strDate
, 5, 2 )
112.
;
$dYear
=
substr
(
$strDate
, 0, 4 ) ;
113.
if
(
$dYear
< 2552 ) {
114.
$dYear
+= 543 ;
115.
}
116.
switch
(
$mode
) {
117.
case
'full'
:
118.
$thMonth
=
array_combine
(
$month_key
,
$month_full
) ;
119.
$new_date
=
"วันที่ "
.
$dDay
.
" เดือน"
.
$thMonth
[
$dMonth
] .
"พ.ศ"
.
$dYear
;
120.
break
;
121.
case
'short'
:
122.
$thMonth
=
array_combine
(
$month_key
,
$month_short
) ;
123.
$new_date
=
$dDay
.
" "
.
$thMonth
[
$dMonth
] .
" "
.
substr
(
$dYear
, 2, 2 ) ;
124.
break
;
125.
case
'digit'
:
126.
$new_date
=
$dDay
.
"/"
.
$dMonth
.
"/"
.
$dYear
;
127.
break
;
128.
}
129.
if
(
$type
==
"datetime"
) {
130.
$dTime
=
substr
(
$strDate
, 11, 8 ) ;
131.
$new_date
=
$new_date
.
" àÇÅÒ "
.
$dTime
.
" ¹."
;
132.
}
133.
return
$new_date
;
134.
}
135.
?>