-
Notifications
You must be signed in to change notification settings - Fork 0
/
basicSearchProcess.php
83 lines (56 loc) · 3 KB
/
basicSearchProcess.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
76
77
78
79
80
81
82
83
<?php
require "connection.php";
$txt = $_POST["t"];
$select = $_POST["s"];
$query = "SELECT * FROM `product`";
if (!empty($txt) && $select == 0) {
$query .= " WHERE `title` LIKE '%" . $txt . "%'";
} else if (empty($txt) && $select != 0) {
$query .= " WHERE `category_id`='" . $select . "'";
} else if (!empty($txt) && $select != 0) {
$query .= " WHERE `title` LIKE '%" . $txt . "%' AND `category_id`='" . $select . "'";
}
?>
<div class="row">
<div class="offset-lg-1 col-12 col-lg-10 text-center">
<div class="row justify-content-center">
<?php
if ("0" != ($_POST["page"])) {
$pageno = $_POST["page"];
} else {
$pageno = 1;
}
$product_rs = Database::search($query);
$product_num = $product_rs->num_rows;
$results_per_page = 10;
$number_of_pages = ceil($product_num / $results_per_page);
$page_results = ($pageno - 1) * $results_per_page;
$selected_rs = Database::search($query . " LIMIT " . $results_per_page . " OFFSET " . $page_results . "");
$selected_num = $selected_rs->num_rows;
for ($x = 0; $x < $selected_num; $x++) {
$selected_data = $selected_rs->fetch_assoc();
?>
<div class="card col-6 col-lg-2 mt-2 mb-2" style="width: 18rem;">
<?php
$product_img_rs = Database::search("SELECT * FROM `images` WHERE `product_id`='" . $selected_data["id"] . "'");
$product_img_data = $product_img_rs->fetch_assoc();
?>
<img src="<?php echo $product_img_data["code"]; ?>" class="card-img-top p-3" style="height: 230px;" />
<div class="card-body ms-0 m-0 text-center">
<h5 class="card-title fs-6 fw-bold"><?php echo $selected_data["title"]; ?></h5>
<span class="card-text text-primary">Rs. <?php echo $selected_data["price"]; ?> .00</span> <br />
<span class="card-text text-warning fw-bold">In Stock</span> <br />
<span class="card-text text-success fw-bold"><?php echo $selected_data["qty"]; ?> Items Available</span><br /><br />
<button class="col-12 btn btn-success">Buy Now</button>
<button class="col-12 btn btn-danger mt-2" onclick='addToCart(<?php echo $selected_data["id"]; ?>);'>Add to Cart</button>
<button class="col-12 btn btn-outline-light mt-2 border border-info" onclick='addToWatchlistSearch(<?php echo $selected_data["id"]; ?>);'>
<i class="bi bi-heart-fill text-dark fs-5" id='heart<?php echo $selected_data["id"]; ?>'></i>
</button>
</div>
</div>
<?php
}
?>
</div>
</div>
</div>