อยากให้ผู้รุ้ช่วยแปลงคำสั่ง while เป็นคำสั่ง for และ do..while หน่อยครับ ขอบคุณคับ
Date :
2016-08-13 02:53:05
By :
Arif
No. 5
Guest
Code
$sql="SELECT * FROM order_detail LEFT OUTER JOIN product on `order_detail`.product_id=product.id WHERE order_id='$id'";
Date :
2016-09-09 21:07:32
By :
อัจฉรา
No. 6
Guest
Code (PHP)
<?
include("../lib/utility.php");
connect_db();
$sql="SELECT * FROM order_detail LEFT OUTER JOIN product on `order_detail`.product_id=product.id WHERE order_id='$id'";
$result=mysql_query($sql);
while ($rs=mysql_fetch_array($result)) {
$sql = "UPDATE product SET prd_qty=prd_qty+$rs[amount] WHERE id=$rs[product_id]";
mysql_query($sql);
}
$sql = "DELETE FROM order_detail WHERE order_id=$id";
mysql_query($sql);
$sql = "DELETE FROM order WHERE id=$id";
mysql_query($sql);
$sql = "DELETE FROM money WHERE keyin=$id";
mysql_query($sql);
echo "";
echo "<meta http-equiv='refresh' content='3;URL=order.php'>";
?>
รบกวนแปลโค๊ดให้หน่อยน่ะค่ะ
Date :
2016-09-09 21:10:01
By :
อัจฉรา
No. 7
Guest
Code (PHP)
<?
session_start();
include("../lib/utility.php");
connect_db();
$address = $_REQUEST["address"];
$cart = $_SESSION["cart"];
$username = $_SESSION["username"];
if ($_SESSION["sss"]==''){
$sql = "SELECT * FROM member WHERE username='$username'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$member_id = $row["id"];
}else{
$sql = "SELECT * FROM admin WHERE username='$username'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$member_id = $row["adminid"];
}
if ($_SESSION["sss"]==''){
$sql = "INSERT INTO `order` (shipping_address, date, member_id,total,money) VALUES('$address', NOW(), $member_id,'$total','0')";
}else{
$sql = "INSERT INTO `order2` (shipping_address, date, member_id,total) VALUES('$address', NOW(), $member_id,'$total')";
} mysql_query($sql);
$order_id = mysql_insert_id(); //Order Detail
foreach ($cart as $product_id => $item) {
if ($_SESSION["sss"]==''){
$sql = "INSERT INTO order_detail (amount, product_id, order_id) VALUES($item[amount], $product_id, $order_id)";
}else{
$sql = "INSERT INTO order_detail2 (amount, product_id, order_id) VALUES($item[amount], $product_id, $order_id)";
} mysql_query($sql);
} foreach ($cart as $product_id => $item) {
$result = mysql_query("update product set prd_qty = prd_qty - '$item[amount]' where id = '$product_id'"); // เช็คสต๊อกสินค้าคงเหลือ
}
unset($_SESSION["cart"]);
?>
รบกวนแปลโค๊ดให้หน่อยน่ะค่ะ
Date :
2016-09-09 21:39:05
By :
อัจฉรา
No. 8
Guest
Code (PHP)
<?
session_start();
include("../lib/utility.php");
connect_db();
$cart = $_SESSION["cart"];
$num_ar = count($cart) ;//$idd=$_SESSION["id"];
$sql = "SELECT * FROM member WHERE username='$username'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
$idd=$row["id"]; //echo $username;
//exit();
$sql = "SELECT *, `order`.order_id as order_id, SUM(order_detail.amount*product.price) as all_price FROM `order`"
. " INNER JOIN member ON `order`.member_id = member.id"
. " INNER JOIN order_detail ON order_detail.order_id = `order`.order_id"//เพิ่มรายการสั่งซื้อ แล้วรายการสินค้า*ราคา
. " INNER JOIN product ON order_detail.product_id = product.id where member_id='$idd' "
. " GROUP BY `order`.order_id"
. " ORDER BY `order`.order_id DESC";
$result = mysql_query($sql) or die(mysql_error());
?>
<?
if ($row["money"]==0){
echo"รอการชำระเงิน";
}else{
$u = "select * from money where keyin='$row[order_id]'";
$uu = mysql_query($u);
$ii = mysql_fetch_array($uu) ;
if ($ii["comment"]=="รอรับสินค้า"){
echo "ส่งสินค้าเรียบร้อยแล้ว";
}else{ echo"รอการตรวจสอบ";
}
}
?>