-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuggest_plant.php
34 lines (28 loc) · 1.1 KB
/
suggest_plant.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
<?php
require_once('lego/DatabaseLego.php');
ConnectDB();
// if the 'term' variable is not sent with the request, exit
if ( !isset($_REQUEST['term']) )
exit;
// connect to the database server and select the appropriate database for use
// $dblink = mysql_connect('localhost', 'root', 'root') or die( mysql_error() );
// mysql_select_db('dibbital');
// query the database table for zip codes that match 'term'
$rs = mysql_query("SELECT * FROM `plants` WHERE (`key` = 'common_name' OR `key` = 'latin_name') AND (`value` LIKE '". mysql_real_escape_string($_REQUEST['term']) ."%') ORDER BY `value` ASC LIMIT 0, 10");
// SELECT id, key, value FROM plants WHERE key = "common_name" AND value LIKE "'. mysql_real_escape_string($_REQUEST['term']) .'%" order by key asc limit 0,10', $dblink);
// loop through each zipcode returned and format the response for jQuery
$data = array();
if ( $rs && mysql_num_rows($rs) )
{
while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) )
{
$data[] = array(
'label' => $row['value'] ,
'value' => $row['pid']
);
}
}
// jQuery wants JSON data
echo json_encode($data);
flush();
?>