 |
|
เอาอย่างนี้นะกันนะครับ
ลองเอาโค๊ดไปรันดูนะครับ ขอโทษที่ไม่รู้จะอธิบายยังงัย
SQL
CREATE TABLE `reserv` (
`id` int(2) NOT NULL,
`name` varchar(10) NOT NULL,
`amount` int(7) NOT NULL,
`price` int(7) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- dump ตาราง `reserv`
--
INSERT INTO `reserv` VALUES (1, 'ห้อง 1', 1, 2000);
INSERT INTO `reserv` VALUES (2, 'ห้อง 2', 2, 3000);
INSERT INTO `reserv` VALUES (3, 'ห้อง 3', 4, 100);
INSERT INTO `reserv` VALUES (4, 'ห้อง 4', 8, 200);
Code (PHP)
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="7%" align="center">ลำดับ</td>
<td width="26%" align="center">ชื่อห้อง</td>
<td width="11%" align="center">จำนวน</td>
<td width="27%" align="center">ราคา</td>
<td width="29%" align="center">รวม</td>
</tr>
<?
$sql="select * from $tb1 "; // ดึงข้อมูลออกมาโชว์ปกติ
$qu=mysql_query($sql);
$i=0;
while($rs=mysql_fetch_array($qu)){
?>
<tr>
<td> <?=$i+1;?></td>
<td> <?=$rs[name];?></td>
<td> <?=$rs[amount];?></td>
<td> <?=$rs[price];?></td>
<td><?=$rs[amount]*$rs[price];?></td>
</tr>
<? $i++;}
$sqlTotle="select sum(amount*price) as totle from $tb1 "; // ทำการ sum ข้อมูลที่เราต้องการแล้วดึงข้อมูลออกมาใช้ปกติ
$quTotle=mysql_query($sqlTotle);
$rsTotle=mysql_fetch_array($quTotle)
?>
<tr>
<td colspan="2">รวม</td>
<td> </td>
<td> </td>
<td> <?=$rsTotle[totle]?></td>
</tr>
</table>
แสดงผล

ลองประยุกต์ดูนะครับ....
|
 |
 |
 |
 |
Date :
2009-12-08 12:38:06 |
By :
martman26 |
|
 |
 |
 |
 |
|
|
 |