-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
55 lines (49 loc) · 1.93 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
<?php
include_once './header.php';
$pdo = pdo_connect_mysql();
?>
<div class="container-fluid">
<?php
$query = "SELECT * FROM product WHERE date_published <= CURDATE() ORDER BY date_published DESC, id DESC LIMIT 6";
$newProducts = $pdo->query($query)->fetchAll(PDO::FETCH_ASSOC);
?>
<div class="product-group card my-3">
<h2 class="align-items-center mx-3 border-bottom">Novi izdelki</h2>
<div class="row">
<?php foreach($newProducts as $product) {
echo productCard($product);
} ?>
</div>
</div>
<?php
$query = "SELECT p.*, AVG(r.rating) AS ratings FROM product p INNER JOIN review r ON p.id = r.product_id WHERE date_published <= CURDATE() GROUP BY p.id ORDER BY ratings DESC LIMIT 6";
$bestRated = $pdo->query($query)->fetchAll(PDO::FETCH_ASSOC);
if($bestRated):
?>
<div class="product-group card my-3">
<h2 class="align-items-center mx-3 border-bottom">Najbolje ocenjeni</h2>
<div class="row">
<?php foreach($bestRated as $product) {
echo productCard($product);
} ?>
</div>
</div>
<?php endif; ?>
<?php
$query = "SELECT DISTINCT p.* FROM product p INNER JOIN product_sale ps ON p.id = ps.product_id INNER JOIN sale s ON ps.sale_id = s.id WHERE date_published <= CURDATE() AND s.date_start <= CURDATE() AND s.date_end >= CURDATE() ORDER BY s.date_start DESC LIMIT 6";
$productsOnSale = $pdo->query($query)->fetchAll(PDO::FETCH_ASSOC);
if($productsOnSale):
?>
<div class="product-group card my-3">
<h2 class="align-items-center mx-3 border-bottom">Novo na razprodaji</h2>
<div class="row">
<?php foreach($productsOnSale as $product) {
echo productCard($product);
} ?>
</div>
</div>
<?php endif; ?>
</div>
<?php
include_once './footer.php';
?>