-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
79 lines (63 loc) · 1.88 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>My Shop</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
</head>
<body>
<?php include('nav.php')?>
<div class="container">
<div class="row">
<div class="col-4">
<img src="https://cdn.shopify.com/s/files/1/0322/5894/9164/files/My_Shop_Logo_Transparent.png?height=628&pad_color=fff&v=1581933721&width=1200" class="img-fluid">
</div>
<div class="col-8">
<div class="row">
<?php
//connecttion
require('dbconnect.php');
//select query
$sql = "SELECT * FROM product";
//execute query
$results = mysqli_query($conn,$sql);
//check if query is query
if ($results) {
# code...
//check if the rows exist
//myqli_num_rows
if (mysqli_num_rows($results)>0) {
# code...
//for every record with - create associate
//loop
while ($record = mysqli_fetch_assoc($results)) {
# code...
//get individual record field as an associative
//key - value
//column name
echo '
<div class="card col-4" style="">
<div class="card-body">
<h5 class="card-title">'.$record['name'].'</h5>
<p class="card-text" rows="3">'.$record['description'].'.</p>
<h4 style="color:#E53206;">Ksh'.$record['cost'].'</h4>
<a href="purchase.php?id='.$record['id'].'" class="btn btn-primary">Buy Now</a>
</div>
</div>
';
}
}else{
echo "<h4>No Products available</h4>";
echo "<a class='btn btn-primary' href='addproduct.php'>Add Product</a>";
}
}else{
echo "Something went wrong!!";
}
?>
</div>
</div>
</div>
<div>
</div>
</div>
</body>
</html>