-
Notifications
You must be signed in to change notification settings - Fork 1
/
home.php
67 lines (44 loc) · 1.72 KB
/
home.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
<?php
header('Content-Type: application/json');
//this script deals with the intent fired on the home screen of the android app
//TESTING: http://54.235.158.91/home.php?action=browse
//output will be the list of gyms and gym id's
////////////////////////////////////////
///////// DB CONNECTION SETUP /////////
//////////////////////////////////
$link = mysql_connect("localhost", "root", "");// access AMAZON server
if(!$link) die('Was unable to connect to Amazon Server!');
if(!mysql_select_db("climbuddy", $link)) die("Was unable to connect to database!");
////////////////////////////////////////
/////// SETUP COMPLETE ////////////////
////////////////////////////////////
//assume we are now connected to DB with access to tables
$action = $_REQUEST['action']; // set local string to action item
if($action == "capture") die("invalid request at this time!");
else if($action == "browse")
{
$output = array(); // JSON response array
$result = mysql_query("SELECT gymID, name FROM Gyms") or die(mysql_error());
//check for empty results
if(mysql_num_rows($result) > 0)
{
//loop through results....
$output["gyms"] = array();
while($row = mysql_fetch_array($result))
{
$gym_info = array();
$gym_info["gymID"] = $row["gymID"];
$gym_info["name"] = $row["name"];
//push single gym information into final output array
array_push($output["gyms"], $gym_info);
}//end while
$output["success"] = 1; //success!
echo json_encode($output); // echoing JSON response which will be the list of gyms
}//end if
else
{ // no gyms found
$output["success"] = 0; // NO SUCCESS!
echo json_encode($output); //we still want to echo something so Android can react appropriately if no gyms exist!
}
}
?>