-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsuggest.php
More file actions
35 lines (31 loc) · 823 Bytes
/
suggest.php
File metadata and controls
35 lines (31 loc) · 823 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
32
33
34
35
<?php
include_once("connect_to_mysql.php");
// Array with name
$a=array();
$sq=mysqli_query($conn,"select Pname from products");
$productCount=mysqli_num_rows($sq);
$i=0;
while($row=mysqli_fetch_array($sq,MYSQLI_ASSOC))
{
array_push($a,$row["Pname"]);
}
// get the q parameter from URL
$q = $_REQUEST["q"];
$hint = "";
// lookup all hints from array if $q is different from ""
if ($q !== "") {
$q = strtolower($q);
$len=strlen($q);
foreach($a as $name) {
if (stristr($q, substr($name, 0, $len))) {
if ($hint === "") {
$hint ="<option>".$name;
} else {
$hint .= "<option>".$name;
}
}
}
}
// Output "no suggestion" if no hint was found or output correct values
echo $hint === "" ? "no suggestion" : $hint;
?>