โค้ด: เลือกทั้งหมด
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ThinClientNetwork : Edit Qty and Price! For Quotation!!!</title>
<link rel="stylesheet" href="../cus/css/style_main.css" />
<script>
function deleteCart(pid) {
if(!confirm('ลบสินค้านี้ ?')) {
return;
}
location = "<?php echo $_SERVER['PHP_SELF']; ?>?pid=" + pid;
}
</script>
</head>
<body>
<?php
include("menutop.php");
include("conn.inc.php");
connect_db();
$cid = $_REQUEST['cid'];
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<?php
if($_POST) {
foreach($_POST as $pid => $qty) {
if(!is_numeric($qty) || $qty <= 0) {
continue;
}
$cid = $_REQUEST['cid'];
$sql = "UPDATE request SET qty = $qty
WHERE pro_id = $pid AND cus_ord_id = '$cid';";
// $sql = "UPDATE request SET qty = $qty
// WHERE pro_id = $pid AND cus_user = '$cus_user';";
@mysql_query($sql);
}
}
else if($_GET['pid']) {
$pid = $_GET['pid'];
$cid = $_REQUEST['cid'];
$sql = "DELETE FROM request WHERE pro_id = $pid AND cus_ord_id = '$cid';";
mysql_query($sql);
}
$cid = $_REQUEST['cid'];
$sql = "SELECT * FROM request
WHERE cus_ord_id = '$cid';";
//$sql = "SELECT * FROM request
// WHERE cus_user = '$cus_user';";
$result = mysql_query($sql);
if(mysql_num_rows($result) == 0) {
echo "<p align=center>ไม่มีสินค้า! </p>";
echo "</form></body></html>";
exit;
}
?>
<table border=1 bordercolor=#cccccc cellpadding=3 align=center style="border-collapse: collapse;">
<caption>รายการสินค้าที่ลูกค้าเลือก</caption>
<tr bgcolor=#ddddff>
<th align=center width=220>สินค้า</th><th width=50>จำนวน</th><th width=50>ราคา</th><th width=80>รวม</th>
</tr>
<?php
$grand_total = 0;
while($cart = mysql_fetch_array($result)) {
$sub_total = $cart['qty'] * $cart['price'] ;
$pid = $cart['pro_id'];
echo "
<tr valign=top>
<td>
[<a href=\"javascript: deleteCart($pid)\" title=ลบรายการนี้>x</a>]
{$cart['pro_name']}
</td>
<td align=center>
<input type=text size=3 name=$pid value={$cart['qty']} />
</td>
<td align=center>{$cart['price']}</td>
<td align=right>$sub_total</td>
</tr>";
$grand_total += $sub_total;
}
?>
<tr>
<td colspan=3 align=center>รวมทั้งหมด</td>
<td align=right><?php echo $grand_total ?></td>
</tr>
</table>
<p align=center>
<input type="button" value="« ย้อนกลับ" onclick="location='req_list.php'" />
<input type="submit" value="คำนวณใหม่" />
</p>
</form>
</body>
</html>
ติดอยู่ว่า ผมใช้ id ในการ วนลูปออกมา
รูปประกอบที่ 1
[ รูปประกอบที่ 1 ]
จากรูป คือใช้ cus_ord_id 2011005 ในการ fetch ข้อมูล คือ pro_id 1101 , 1102
จะเป็นดังนี้ [ รูปประกอบที่ 2
ที่นี้เวลาจะเขียนโค้ดแก้ไข ปรากฎว่า เวลาใส่ข้อมูลลงไปใหม่ ปรากฎว่า มันไม่สามารถแก้ไขได้
ช่วย แนะนำโค้ดแก้ไข จำนวน และ ราคาในรูปแบบประมาณนี้ หน่อยครับ