-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource_cities.php
50 lines (36 loc) · 914 Bytes
/
source_cities.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
<?php
$con = mysqli_connect('localhost','root','root');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
else{
}
mysqli_select_db($con,'railwayreservation');
$q = " select SOURCE from train" ;
$query = mysqli_query($con,$q);
$trains=array();
if(mysqli_num_rows($query) > 0){
while ($result = mysqli_fetch_array($query)){
if(!(in_array($result['SOURCE'],$trains))){
$trains[]=$result['SOURCE'];
}
}
}
$q = $_REQUEST["q"];
$hint = "";
if ($q !== "") {
$q = strtolower($q);
$len=strlen($q);
foreach($trains as $name) {
if (stristr($q, substr($name, 0, $len))) {
if ($hint === "") {
$hint = $name;
} else {
$hint .= "<br> $name";
}
}
}
}
echo $hint === "" ? "no trains" : $hint;
mysqli_close($con);
?>