This repository was archived by the owner on Mar 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcart.php
59 lines (57 loc) · 2.63 KB
/
cart.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php include_once("header.php");
if(isset($_POST["amount"])){ // บันทึกข้อมูลของ request edit
$order_id = $_POST["order_id"];
$amount = $_POST["amount"];
if($amount == 0){
mysqli_query($conn,"DELETE FROM user_order WHERE order_id = '$order_id'");
header("location:cart.php");
}else{
mysqli_query($conn,"UPDATE user_order SET order_amout = '$amount' WHERE order_id = '$order_id'");
header("location:cart.php");
}
}
if(isset($_GET["edit"])){ // ถ้า request edit มา
$selectfood = $dbcon->prepare("SELECT * FROM foodlist WHERE fl_id = '".$_GET["fid"]."'");
$selectfood->execute();
$rowa = $selectfood->fetch();
?>
<center><h1>แก้ไขจำนวน</h1>
<form method="post">
<img src="upload/food/<?php echo $rowa["fl_image"];?>" style="max-width:150px;"><br><br>
<?php echo $rowa["fl_name"];?><br>
จำนวน <input name="amount" type="number" min="0" value="<?php echo $_GET["amout"];?>">
<input type="hidden" name="order_id" value="<?php echo $_GET["edit"];?>">
<br><br><button>บันทึก</button>
</form>
<?php }else{ // หน้าหลักแบบไม่มี request
?>
<center><h1>รายการสินค้าในตระกร้าของ <?php echo $_SESSION["fullname"];?></h1>
<?php
?>
<table border="1">
<th>รูปภาพ</th>
<th>ชื่ออาหาร</th>
<th>ประเภทอาหาร</th>
<th>ราคา</th>
<th>จำนวน</th>
<th>ราคารวม</th>
<tr>
<?php
$mycart = $dbcon->prepare("SELECT * FROM user_order as uo JOIN food_category as fc JOIN foodlist as fl ON uo.order_fl_id = fl.fl_id AND fl.fl_category = fc.fc_id WHERE order_owner_u_id = '$user_id' AND order_ispaid = '0'");
$mycart->execute();
$sumprice = 0;
while($row = $mycart->fetch(PDO::FETCH_ASSOC)){
$sumone = $row["fl_price"] * $row["order_amout"]?>
<td><img src="upload/food/<?php echo $row["fl_image"];?>" style="max-width:150px;"></td>
<td><?php echo $row["fl_name"];?></td>
<td><center><?php echo $row["fc_name"];?></center></td>
<td><?php echo $row["fl_price"];?></td>
<td><?php echo $row["order_amout"];?> บาท</td>
<td><?php echo $sumone;?> บาท</td>
<td><a href="cart.php?edit=<?php echo $row["order_id"];?>&amout=<?php echo $row["order_amout"];?>&fid=<?php echo $row["fl_id"];?>">แก้ไข</a></td>
<tr>
<?php $sumprice = $sumprice + $sumone; }?>
<tr>
<td><td><td><td><td><td><?php echo $sumprice;?> บาท<td colspan="2"><center><a href="checkout.php">สั่งซื้อ</a></center></td>
</table>
<?php } ?>