01.
<?
02.
$query
= mysql_query("
03.
SELECT product.id_prd,sum(order_detail.number)
as
order_num,in_stock_prd,name_prd
04.
FROM order_detail,product
05.
WHERE product.id_prd=order_detail.ref_id_prd
06.
GROUP BY ref_id_prd
07.
ORDER BY order_num DESC");
08.
$i
=1;
09.
?>
10.
<p align=
"center"
><center><h3>ยอดสินค้าทั้งหมด</center></h3></p>
11.
<table align=
"center"
border=
"1"
cellpadding=
"8"
>
12.
<tr bgcolor=
"#00FF00"
>
13.
<td align=
"center"
><div align=
"center"
>ลำดับ</div></td>
14.
<td align=
"center"
><div align=
"center"
>รายการสินค้า</div></td>
15.
<td align=
"center"
><div align=
"center"
>ยอดทั้งหมด</div></td>
16.
<td align=
"center"
><div align=
"center"
>ขายแล้ว</div></td>
17.
<td align=
"center"
><div align=
"center"
>คงเหลือในคลังทั้งหมด</div></td>
18.
</tr>
19.
<?php
while
(
$row
= mysql_fetch_array(
$query
)) { ?>
20.
<tr>
21.
<td align=
"center"
><?
echo
$row
[
'id_prd'
]?></td>
22.
<?
$id
=
$row
[
'id_prd'
];?>
23.
<td align=
"center"
><?
echo
$row
[
'name_prd'
]?></td>
24.
<td align=
"center"
><?php
echo
$row
[
'in_stock_prd'
]; ?></td>
25.
<td align=
"center"
><?php
echo
$row
[
'order_num'
]; ?></td>
26.
<?
$sum
=
$row
[
'in_stock_prd'
]-
$row
[
'order_num'
];?>
27.
<td align=
"center"
><?php
echo
$sum
; ?></td>
28.
</tr>
29.
<?php
$i
++; } ?>
30.
</table>
31.
<p> </p>
32.
</td>
33.
</tr>
34.
</table>
35.
<?
36.
$query2
=
"UPDATE product SET in_stock_prd='"
.
$sum
.
"' WHERE id_prd='"
.
$id
.
"'"
;
37.
38.
mysql_query(
$query2
)
or
die
(mysql_error());
39.
?>