/
list.php
61 lines (59 loc) · 1.67 KB
/
list.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
<?php
include_once 'tools.php';
//$query = "SELECT * FROM product";
//$prodList = array();
//if ($result = $connect->query($query)) {
// while ($row = $result->fetch_object()) {
// $prodList[] = $row;
//}
$product = new Product();
$prodList = $product->findAll($connect);
//$connect->close();
?>
<?php
if (!empty($prodList)) {
echo '<ul class="product-list">';
$index = 1;
foreach ($prodList as $product) {
$itemClass = (($index % 2 === 0) ? 'item-even' : 'item-odd');
?>
<li class="item <?php echo $itemClass; ?>">
<div class="index">
<?php
echo $index++;
?>
</div>
<div class="title">
<?php
echo $product->title;
?>
</div>
<div class="price">
<?php
echo $product->price;
?>
</div>
<div class="quantity">
<?php
echo $product->quantity;
?>
</div>
<div class="category-title">
<?php
$category = new Category();
echo $category->findById($connect, $product->category_id)->title;
?>
</div>
<div class="controls">
<a class="a-edit" href="edit.php?productId=<?= $product->id; ?>">Edit</a>
<a class="a-del" href="delete.php?productId=<?= $product->id; ?>">Delete</a>
</div>
</li>
<?php
}
echo '</ul>';
} else {
echo "<h4>No products found!</h4>";
}
?>
<a class="a-edit" href="add.php">Add new product</a>