-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetData.php
More file actions
54 lines (40 loc) · 1.02 KB
/
getData.php
File metadata and controls
54 lines (40 loc) · 1.02 KB
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
<?php
//Get the action of post request.
$jsonAction = $_POST[action];
$jsonSource = $_POST[dataSource];
//Open connection.
$con = mysql_connect('localhost', 'root', 'root');
if (!$con){
die('Could not connect: ' . mysql_error());
}
//Choose database.
mysql_select_db("Pond", $con);
//Get required data.
if($jsonSource == "Original"){
$lilyPads = mysql_query("select * from Leafs", $con);
$flowers = mysql_query("select * from Flowers", $con);
}
else if($jsonSource == "Saved"){
$lilyPads = mysql_query("select * from savedLeafs", $con);
$flowers = mysql_query("select * from savedFlowers", $con);
}
//Put data in array.
$i = 0; $lilyPadsJson = null; $flowersJson = null;
while($row = mysql_fetch_array($lilyPads)){
$lilyPadsJson[$i] = $row;
$i++;
}
$i = null;
$i=0;
while($row = mysql_fetch_array($flowers)){
$flowersJson[$i] = $row;
$i++;
}
$i = null;
//Post to front-end.
if($jsonAction == "getPads"){
echo json_encode($lilyPadsJson);
}
else if($jsonAction == "getFlowers"){
echo json_encode($flowersJson);
}