|
 |
|
มีปัญหาเรื่องการ update ที่ละหลาย record ครับ มือใหม่เรื่อง loop ครับ |
|
 |
|
|
 |
 |
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?
include "conn.php";
$id_bill = $_POST['idb'];
$cus =$_POST['id_cus'];
$cdate = $_POST['date'];
$cdis = $_POST['cdis'];
$tp = $_POST['tp'];
$pay = $_POST['dd'];
$pay_date = $_POST['pay_date'];
$sum_dis = $_POST['cc'];
$re_pay = $_POST['ff'];
$note = $_POST['note'];
$ts = ceil($tp-($tp*$cdis)/(100+$cdis));
if(empty($cus))
{
echo "<script>alert(' กรุณากรอกรหัสสมาชิกครับ !!');history.back();</script>";
exit();
}
$s = "select * from customer_com where cidb='$id_bill' " ;
$q = mysql_query($s)or die("error=$s");
$a = mysql_fetch_array($q);
if($a['cidb'] == $id_bill)
{
echo "<script>alert(' รหัสใบสั่งซื้อนี้ได้ออกไปแล้วครับ !!');history.back();</script>";
exit();
}
$s = "select * from center where id_member='$id_cus' " ;
$q = mysql_query($s)or die("error=$s");
$a = mysql_fetch_array($q);
$idm = $a['id_member'];
$fname = $a['center_fname'];
$lname = $a['center_lname'];
$name = "$fname $lname";
$id_ad = $a['id_advice'];
$na_ad = $a['name_advice'];
$sqlc = "select * from sell_com where cid_bill='$id_bill' ";
$queryc = mysql_query($sqlc) or die ("error=$sqlc");
$num = mysql_num_rows($queryc);
for($i=1;$i<$num;$i++)
{
$row = mysql_fetch_array($queryc);
$no = $row['cno'];
$idb = $row['cid_bill'];
$idp = $row['cid_product'];
$am = $row['camount'];
$date = $row['cdate'];
$sta = 1;
$sqla = "update sell_com set
cno = '$no[$i]',
cid_bill = '$idb[$i]' ,
cid_product = '$idp[$i]',
camount = '$am[$i]',
cdate = '$date[$i]',
csta = '$sta[$i]' where cid_bill='$idb[$i]' ";
mysql_query($sqla) or die ("errora=$sqla");
}
$sql = "insert into customer_com values('$idb' , '$cus' , '$name' ,'$id_ad' , '$na_ad' ,'$cdate' , '$tp' , '$cdis' , '$ts' , '$pay' , '$pay_date' , '$note')";
mysql_query($sql) or die ("errorb=$sql");
echo "<script>alert(' ยืนยันการซื้อสินค้า');window.location='print_sell_com.php';</script>";
?>
หลักการคือมันจะไปตรวจสอบฐานข้อมูลแล้วทำการเปลี่ยนค่า $sta ให้เป็น 1 แต่ปัญหาคือมันทำการเปลี่ยนค่าแค่ record สุดท้ายมันไม่ยอมวนเปลี่ยนค่านะครับ
ปล. เรื่องการ loop update นี้เป็นครังแรกที่ใช้ครับช่วยแนะนำทีอีกอย่าง code ผมมันดูเกินจำเป็นไหมครับ
ผมรู้สึกว่า code ผมบางส่วนมันดูเกินจำเป็นไป
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2011-04-06 17:28:46 |
By :
excerberia |
View :
1269 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 04
|