forked from tectronics/ChristianFlatshare
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathajax-autocomplete.php
More file actions
44 lines (34 loc) · 1012 Bytes
/
ajax-autocomplete.php
File metadata and controls
44 lines (34 loc) · 1012 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
36
37
38
39
40
41
42
43
44
<?php
// Autoloader
require_once 'web/global.php';
connectToDB();
header('Content-type: application/json');
// If the home page auto-completer posted to this page
if (isset($_POST['value'])) {
$v = trim($_POST['value']);
$query = "
SELECT CONCAT(place_name,', ',cj.county, ' (',cj.postcode,')')
FROM cf_uk_places ckp,
cf_jibble_postcodes cj
WHERE ckp.place_name LIKE '".$v."%'
AND ckp.postcode = cj.postcode
UNION
SELECT CONCAT(cj.postcode, ' ', place_name,', ',cj.county)
FROM cf_uk_places ckp,
cf_jibble_postcodes cj
WHERE ckp.postcode LIKE '".$v."%'
AND ckp.postcode = cj.postcode
LIMIT 0,20
";
$result = mysqli_query($GLOBALS['mysql_conn'], $query);
$results = array();
if (mysqli_num_rows($result) !== FALSE) {
while($row = mysqli_fetch_row($result)) {
$results[] = $row[0];
}
} else {
$results[] = "No results found";
}
print json_encode($results);
}
?>