-
Notifications
You must be signed in to change notification settings - Fork 0
/
category.php
60 lines (46 loc) · 1.13 KB
/
category.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
<?php
// DB Connection
require_once 'db.php';
session_start() ;
function isAdmin() {
return $_SESSION["user"]["role"] == 2 ;
}
if(isset($_GET['id'])){
$categoryid=$_GET['id'];
}
if(isset($_GET['name'])){
$categoryname= $_GET['name'];
}
?>
<?php
require_once 'header.php';
?>
<h2><?php echo $categoryname; ?> | Products</h2>
<table>
<tr class="bold"><td>Picture</td><td>Product</td><td>Price</td></tr>
<?php
try {
$sql = "select * from product";
$stmt = $db->query($sql) ;
if ( $stmt->rowCount() > 0) {
foreach ( $stmt as $item) {
if ($item['category']==$categoryid) {
echo '<tr>' ;
echo "<td><img src='{$item['photo']}' width='80px'; ></td>" ;
echo "<td><a href='product.php?id={$item['id']}'>{$item['name']}</td>" ;
echo '<td>' . $item['price'] . ' $</td>' ;
echo '<td>' . $item['stock'] . '</td>' ;
echo '</tr>' ;
}
}
} else {
echo '<tr><td>No records yet.</td></tr>' ;
}
} catch( Exception $ex) {
echo '<p>Query error ' . $ex->getMessage() . '</p>' ;
}
?>
</table>
<?php
require_once 'footer.php';
?>