-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchDatabase.php
49 lines (38 loc) · 1.17 KB
/
searchDatabase.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
<?php
require_once('lego/DatabaseLego.php');
ConnectDB();
$plantName = strtolower($_GET['plantName']);
$query = mysql_query("SELECT * FROM 'plants' WHERE 'key' = 'common_name' AND 'value' LIKE '%".mysql_real_escape_string($plantName)."%'");
// if(array_key_exists('plantType', $_GET)){
// $plantType = $_GET['plantType'];
// $query .= " AND plantType = $plantType";
// }
// if(array_key_exists('plantType', $_GET)){
// $plantMaintenance = $_GET['plantMaintenance'];
// $query .= " AND plantMaintenance = $plantMaintenance";
// }
// if(array_key_exists('plantSize', $_GET)){
// $plantSize = $_POST['plantSize'];
// $query .= " AND plantSize = $plantSize";
// }
$num_rows = mysql_num_rows($query);
$return = array();
$plants = array();
if($num_rows != 0){
while($result = mysql_fetch_assoc($query)){
$plant = $result["common_name"];
$lname = $result["latin_name"];
$id = $result['id'];
$plant = array(
'id'=>$id,
'name'=>$plant,
'latin_name'=>$lname
);
array_push($plants,$plant);
}
$return['plants'] = $plants;
}else{
$return['num'] = 0;
};
echo json_encode($return);
?>