-
Notifications
You must be signed in to change notification settings - Fork 0
/
suggest.php
42 lines (34 loc) · 849 Bytes
/
suggest.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
<?php
/*
* Usage: suggest.php?part=[partial word for suggestion]
*
* Response
* ---------
* Type: JSON
* Data:
* {
* 'words' : ['word1','word2','word3']
* }
*
*/
// Get the word
$part = $_GET['part'].'%';
// Connect to the database
include('config.php');
$con = mysql_connect($host,$user,$pass);
if (!$con){
echo "Unable to connect";
}
mysql_select_db($dbname,$con);
$response = array();
$words = array();
$query = mysql_query("SELECT * FROM raw_words WHERE word LIKE '{$part}'");
while($row=mysql_fetch_array($query))
{
$title=$row['word'];
$words[] = $title;
}
$response['words'] = $words;
header("Content-type: application/json");
echo json_encode($response);
?>