-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetdiffortc.php
88 lines (59 loc) · 2.42 KB
/
getdiffortc.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
header('Content-Type: application/json');
//this script returns a list of difficulties OR tapeColors for the requested gym
//SAMPLE TEST: http://54.235.158.91/getdiffortc.php?action=tapeColor&gymID=1
//SAMPLE TEST2: http://54.235.158.91/getdiffortc.php?action=difficulty&gymID=1
mysql_connect("localhost", "root", "") or die("Error: Unable to connect to database");
mysql_select_db("climbuddy") or die("Error: Unable to choose correct database");
$action = $_REQUEST['action'];//will be either "difficulty" OR "tapeColor"
$gymID = $_REQUEST['gymID']; //needed for query to be specific to a gym
if($action == "difficulty")
{
$output = array(); // JSON response array
$result = mysql_query("SELECT difficulty FROM Climbs WHERE gymID = '$gymID' GROUP BY difficulty ORDER BY difficulty") or die(mysql_error());
if(mysql_num_rows($result) > 0)
{
//loop through results....
$output["difficulties"] = array();
while($row = mysql_fetch_array($result))
{
$climb_info = array();
$climb_info["difficulty"] = $row["difficulty"];
//push single climbs information into final output array
array_push($output["difficulties"], $climb_info);
}//end while
$output["success"] = 1; //success!
echo json_encode($output); // echoing JSON response which will be the list of climbs
}//end if
else
{ // no climbs found
$output["success"] = 0; // NO SUCCESS!
echo json_encode($output); //we still want to echo something so Android can react appropriately if no climbs exist!
}
}//end if
else if($action = "tapeColor")
{
$output = array(); // JSON response array
$result = mysql_query("SELECT tapeColor FROM Climbs WHERE gymID = '$gymID' GROUP BY tapeColor") or die(mysql_error());
if(mysql_num_rows($result) > 0)
{
//loop through results....
$output["tapeColors"] = array();
while($row = mysql_fetch_array($result))
{
$climb_info = array();
$climb_info["tapeColor"] = $row["tapeColor"];
//push single climbs information into final output array
array_push($output["tapeColors"], $climb_info);
}//end while
$output["success"] = 1; //success!
echo json_encode($output); // echoing JSON response which will be the list of climbs
}//end if
else
{ // no climbs found
$output["success"] = 0; // NO SUCCESS!
echo json_encode($output); //we still want to echo something so Android can react appropriately if no climbs exist!
}
}//end else if
mysql_close($link);
?>