-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetData.php
More file actions
60 lines (38 loc) · 1.43 KB
/
setData.php
File metadata and controls
60 lines (38 loc) · 1.43 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
<?php
//Get the action of post request.
$jsonAction = $_POST[action];
$jsonData = $_POST[dataArray];
//Decode Json data to PHP array.
$arrayData = json_decode($jsonData, true);
//Open database connection.
$con = mysql_connect('localhost', 'root', 'root');
if (!$con){
die('Could not connect: ' . mysql_error());
}
//Choose database.
mysql_select_db("Pond", $con);
//Process the data based on Action.
if($jsonAction == "setPads"){
saveLilyPads($arrayData, $con);
}
else if($jsonAction == "setFlowers"){
saveFlowers($arrayData, $con);
}
//Save lily pads data to database.
function saveLilyPads($array, $c){
$updateCount = sizeof($array);
for($i = 0; $i < $updateCount; $i++){
mysql_query("UPDATE savedLeafs SET PosX = ".$array[$i]['PosX']." WHERE ID = ".($i + 1), $c);
mysql_query("UPDATE savedLeafs SET PosY = ".$array[$i]['PosY']." WHERE ID = ".($i + 1), $c);
mysql_query("UPDATE savedLeafs SET jointDistance = ".$array[$i]['jointDistance']." WHERE ID = ".($i + 1), $c);
}
echo "LilyPads Saved";
}
function saveFlowers($array, $c){
$updateCount = sizeof($array);
for($i = 0; $i < $updateCount; $i++){
mysql_query("UPDATE savedFlowers SET PosX = ".$array[$i]['PosX']." WHERE ID = ".($i + 1), $c);
mysql_query("UPDATE savedFlowers SET PosY = ".$array[$i]['PosY']." WHERE ID = ".($i + 1), $c);
mysql_query("UPDATE savedFlowers SET expandStatus = ".$array[$i]['expandStatus']." WHERE ID = ".($i + 1), $c);
}
}