-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshopnow.php
135 lines (113 loc) · 4.92 KB
/
shopnow.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your | Shop</title>
<link rel="icon" href="webimage/shopicon.png" type="image/png">
<link rel="stylesheet" href="css/bootstrap.min.css">
<style>
.shoppagebg {
color: white;
background-image: url('webimage/bg2.jpg');
background-size: cover;
}
</style>
</head>
<body>
<?php
include('connection.php');
include('header.php');
?>
<div class="shoppagebg">
<div class="container">
<h2 style="text-align: center; padding-top:100px">All Product List</h2>
<form action="" method="post" name="myForm" onsubmit="return validateForm()" autocomplete="off">
<input type="text" name="search_name" placeholder="Search by Product Name">
<button type="submit">Search</button><i id="search_name" style="color: red;font-size:16px;font-weight:bold; padding-left:10px;"></i>
</form>
<hr>
<!-- Fetching the data from the database -->
<div class="row">
<?php
//For Searching-->
if (isset($_POST['search_name'])) {
$recv = $_POST['search_name'];
}
// FOR getting the page number from the URL
global $get_page;
if (isset($_GET['page'])) {
$get_page = $_GET['page'];
}
if ($get_page == "" || $get_page == "1") {
$target_page = 1;
} else {
$target_page = $_GET['page'];
}
//determine the sql LIMIT starting number for the results on the displaying page
$page_first_result = ($target_page - 1) * 12;
global $recv;
$sql = "SELECT * FROM `products` WHERE `product_name` LIKE '%$recv%' ORDER BY product_id DESC LIMIT $page_first_result,12";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$myimage = $row['image'];
?>
<!-- Put all the values here from the database -->
<div class="card position-relative" style="width: 18rem;margin: 20px; height:370px;">
<div class="d-flex justify-content-center py-2">
<?php
echo "<img src ='images/$myimage' height=200 width=200>";
?>
</div>
<div class="card-body">
<h5 class="card-title"><?php echo substr($row['product_name'], 0, 20); ?></h5>
<p class="card-text">Price: <span style="font-size: 25px;font-weight:bold">৳</span><?php echo $row['price']; ?></p>
<a href="productdetails.php?id=<?php echo $row['product_id']; ?>" class="btn btn-primary" style="position: absolute; bottom: 10px;">Buy Now</a>
</div>
</div>
<?php
}
?>
</div>
<div style="display: flex;justify-content:center;">
<nav aria-label="...">
<ul class="pagination">
<li class="page-item disabled">
<span class="page-link">Previous</span>
</li>
<?php
// For pagination -->
$sql1 = "SELECT * FROM `products`";
$result1 = mysqli_query($conn, $sql1);
$count = mysqli_num_rows($result1);
$i = ($count / 12);
$page = ceil($i);
for ($target = 1; $target <= $page; $target++) {
?>
<li class="page-item"><a class="page-link" href="shopnow.php?page=<?php echo $target; ?>"><?php echo $target; ?></a></li>
<?php
}
?>
<li class="page-item disabled">
<a class="page-link" href="#">Next</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<?php include('footer.php') ?>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
<!-- Script for form validation of Product search box -->
<script>
function validateForm() {
let x = document.forms["myForm"]["search_name"].value;
if (x == "") {
document.getElementById("search_name").innerHTML = "Product Name must be filled out!!"
return false;
}
}
</script>