-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.php
More file actions
31 lines (26 loc) · 940 Bytes
/
search.php
File metadata and controls
31 lines (26 loc) · 940 Bytes
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
<?php
if (isset($_GET['q'])) {
$query = $_GET['q'];
$conn = new mysqli("localhost", "root", "", "kutnik_store");
if ($conn->connect_error) {
die("Błąd połączenia: " . $conn->connect_error);
}
$stmt = $conn->prepare("SELECT id, nazwa, image_url_1 FROM items WHERE nazwa LIKE ? LIMIT 5");
$searchTerm = '%' . $query . '%';
$stmt->bind_param('s', $searchTerm);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$id = $row['id'];
$image_url = $row['image_url_1'];
$nazwa = $row['nazwa'];
echo '<a class="div_a" href="produkt.php?id=' . $id . '"><div class="single-search-product">';
echo '<img src="' . $image_url . '" alt="' . $nazwa . '"';
echo '<p>' . $nazwa . '</p>';
echo '<br>';
echo '</div></a>';
}
$stmt->close();
$conn->close();
}
?>