-
Notifications
You must be signed in to change notification settings - Fork 0
/
sortby_search.php
59 lines (38 loc) · 2.14 KB
/
sortby_search.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
<?php
define('Access', TRUE);
include "./AdditionalPHP/startSession.php";
// <!--========== PHP CONNECTION TO DATABASE: MALAKO ==========-->
include_once 'connection.php';
include_once 'numOfItemsInCart.php';
// QUERIES:
$Q_sortby_price_asc = "SELECT * FROM products ORDER BY p_price ASC; "; //sort all products by price low to high
$Q_sortby_price_desc = "SELECT * FROM products ORDER BY p_price DESC; "; //sort all products by price high to low
//SORT BY PRICE TYPE:
if($_REQUEST['sortby']==1){ // 1 --> low to high
$result_sortby =mysqli_query($conn, $Q_sortby_price_asc);
}
elseif($_REQUEST['sortby']==2){// 2 --> high to low
$result_sortby =mysqli_query($conn, $Q_sortby_price_desc);
}
//DISPLAY SORTED RESULTS
while($row_product = mysqli_fetch_assoc($result_sortby)){
$product_id = $row_product['productID'];
echo ' <div class="featured__products" id="product__card">
<div class="featured__box">
<div class="featured__new">NEW</div>
<div class=""><a href="product.php?product_id='.$product_id.' "><i class="bx bxs-cart-add bx-tada-hover featured__new_cart"></i></a></div>
<a href="product.php?product_id='.$product_id.'" >
<img src="'.$row_product['p_img'].'" alt="" class="featured__img avoid__clicks"
style="
object-fit: cover;
width: 232px;
height: 232px;" />
</a>
</div>
<div class="featured__data">
<a href="product.php?product_id='.$product_id.'" class="product__name" id="product__name"style="text-decoration: none;">'.$row_product['p_name'].'</a></br>
<span class="featured__price">Rs '.$row_product['p_price'].'</span>
</div>
</div> ';
}
?>