-
Notifications
You must be signed in to change notification settings - Fork 0
/
product.php
75 lines (75 loc) · 2.62 KB
/
product.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
<?php include('header.php'); ?>
<body>
<?php include('navbar.php'); ?>
<div class="container">
<h1 class="page-header text-center">PRODUCTS CRUD</h1>
<div class="row">
<div class="col-md-12">
<select id="catList" class="btn btn-default">
<option value="0">All Category</option>
<?php
$sql="select * from category";
$catquery=$conn->query($sql);
while($catrow=$catquery->fetch_array()){
$catid = isset($_GET['category']) ? $_GET['category'] : 0;
$selected = ($catid == $catrow['categoryid']) ? " selected" : "";
echo "<option$selected value=".$catrow['categoryid'].">".$catrow['catname']."</option>";
}
?>
</select>
<a href="#addproduct" data-toggle="modal" class="pull-right btn btn-primary"><span class="glyphicon glyphicon-plus"></span> Product</a>
</div>
</div>
<div style="margin-top:10px;">
<table class="table table-striped table-bordered">
<thead>
<th>Photo</th>
<th>Product Name</th>
<th>Price</th>
<th>Action</th>
</thead>
<tbody>
<?php
$where = "";
if(isset($_GET['category']))
{
$catid=$_GET['category'];
$where = " WHERE product.categoryid = $catid";
}
$sql="select * from product left join category on category.categoryid=product.categoryid $where order by product.categoryid asc, productname asc";
$query=$conn->query($sql);
while($row=$query->fetch_array()){
?>
<tr>
<td><a href="<?php if(empty($row['photo'])){echo "upload/noimage.jpg";} else{echo $row['photo'];} ?>"><img src="<?php if(empty($row['photo'])){echo "upload/noimage.jpg";} else{echo $row['photo'];} ?>" height="30px" width="40px"></a></td>
<td><?php echo $row['productname']; ?></td>
<td>₱ <?php echo number_format($row['price'], 2); ?></td>
<td>
<a href="#editproduct<?php echo $row['productid']; ?>" data-toggle="modal" class="btn btn-success btn-sm"><span class="glyphicon glyphicon-pencil"></span> Edit</a> || <a href="#deleteproduct<?php echo $row['productid']; ?>" data-toggle="modal" class="btn btn-danger btn-sm"><span class="glyphicon glyphicon-trash"></span> Delete</a>
<?php include('product_modal.php'); ?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<?php include('modal.php'); ?>
<script type="text/javascript">
$(document).ready(function(){
$("#catList").on('change', function(){
if($(this).val() == 0)
{
window.location = 'product.php';
}
else
{
window.location = 'product.php?category='+$(this).val();
}
});
});
</script>
</body>
</html>