-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.php
90 lines (85 loc) · 2.2 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
include('session.php');
include('config.php');
?>
<style>
table{
border-collapse:collapse;
border: 1px solid black;
}
tr td, tr th {
border:1px solid black;
padding:10px;
}
</style>
<table>
<tr>
<th>id</th>
<th>name</th>
<th>qty</th>
<th>price</th>
<th>total</th>
<th>tool</th>
</tr>
<?php
if(isset($_SESSION['cart'])){
$cart = $_SESSION['cart'];
$cartLength = count($cart);
$total = 0;
for($i=0; $i< $cartLength;$i++):
$total += $cart[$i]['price']*$cart[$i]['qty'];
?>
<tr>
<td><?php echo $cart[$i]['id']; ?></td>
<td><?php echo $cart[$i]['name']; ?></td>
<td><?php echo $cart[$i]['qty']; ?></td>
<td><?php echo number_format($cart[$i]['price']) . " ₭"; ?></td>
<td><?php echo number_format($cart[$i]['price']*$cart[$i]['qty']) . " ₭"; ?></td>
<td><a href="cart_delete.php?id=<?php echo $cart[$i]['id'] ?>">delete</a></td>
</tr>
<?php
endfor;
?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td style="color:red;"><?php echo number_format($total) . " ₭";?></td>
<td></td>
</tr>
<?php
}
?>
</table>
<a href='cart_confirm.php' style="padding:10;border:1px solid blue; display:block;width: 100px;margin:10px">confirm</a>
<br/>
<br/>
<table>
<tr>
<th>id</th>
<th>image</th>
<th>name</th>
<th>description</th>
<th>price</th>
<th>instock</th>
<th>tool</th>
</tr>
<?php
$sql = "SELECT * FROM products";
$result = $conn->query($sql);
while($row=$result->fetch_assoc()):
?>
<tr>
<td><?php echo $row['id'] ?></td>
<td><img src="<?php echo $row['image'] ?>" alt="" style="height:50px;width:auto"></td>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['description'] ?></td>
<td><?php echo $row['price'] ?></td>
<td><?php echo $row['instock'] ?></td>
<td><a href="cart_add.php?id=<?php echo $row['id'] ?>">add to cart</a></td>
</tr>
<?php
endwhile;
?>
</table>