-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch-items.php
31 lines (29 loc) · 931 Bytes
/
fetch-items.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
<?php
// items tablomuzdaki item_name sütunua göre filtreleme yapıyoruz
require_once 'db.php';
try{
if(isset($_REQUEST["term"])){
// create prepared statement
$sql = "SELECT * FROM items WHERE item_name LIKE :term";
$stmt = $db->prepare($sql);
$term = $_REQUEST["term"] . '%';
// bind parameters to statement
$stmt->bindParam(":term", $term);
// execute the prepared statement
$stmt->execute();
if($stmt->rowCount() > 0){
while($row = $stmt->fetch()){
echo '<div class="element" style="margin-top:2px;">' . $row["item_name"] . '</div>';
}
} else{
echo '<div class="element">Eşleşme bulunamadı</div>';
}
}
} catch(PDOException $e){
die("ERROR: Could not able to execute $sql. " . $e->getMessage());
}
// Close statement
unset($stmt);
// Close connection
unset($db);
?>