-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclimbinfo.php
97 lines (81 loc) · 3.5 KB
/
climbinfo.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
89
90
91
92
93
94
95
96
97
<?php
//this script retrieves the requested climb with all of its information
//specifically from the Climbs table
//TESTING: http://54.235.158.91/climbinfo.php?climb_id=1
header('Content-Type: application/json');
mysql_connect("localhost", "root", "") or die("Error: Unable to connect to database");
mysql_select_db("climbuddy") or die("Error: Unable to choose correct database");
$cid = $_REQUEST["climb_id"];
//we want the android to call this script with the specified CLIMB and CLIMB_ID
$output = array(); // JSON response array
$result = mysql_query("SELECT * FROM Climbs WHERE climbID = '$cid'") or die(mysql_error());
if(mysql_num_rows($result) > 0)
{
$output["climb"] = array();
$row = mysql_fetch_array($result);
$climb_info = array();
$climb_info["difficulty"] = $row["difficulty"];
$climb_info["tapeColor"] = $row["tapeColor"];
$climb_info["pictureURL"] = $row["pictureURL"];
$climb_info["name"] = $row["name"];
array_push($output["climb"], $climb_info);
$commentResults = mysql_query("SELECT * FROM Comments WHERE climbID = '$cid'") or die(mysql_error());
$output["comments"] = array();
if(mysql_num_rows($commentResults) > 0) {
$comment = array();
while ($r = mysql_fetch_array($commentResults)) {
$comment["commentID"] = $r["commentID"];
$comment["comment"] = $r["comments"];
$comment["user"] = $r["username"];
array_push($output["comments"], $comment);
}
}
$betaVids = mysql_query("SELECT * FROM BetaVideos WHERE climbID = '$cid'") or die(mysql_error());
$output["betaVideos"] = array();
if(mysql_num_rows($betaVids)>0) {
$betaVideo = array();
while ($r = mysql_fetch_array($betaVids)) {
$betaVideo["betaID"] = $r["betaID"];
$betaVideo["videoURL"] = $r["videoURL"];
$betaVideo["username"] = $r["username"];
$betaVideo["dateAdded"] = $r["dateAdded"];
$betaVideo["rating"] = $r["rating"]; // probably should take rating out of this and make it separate from videos
array_push($output["betaVideos"], $betaVideo);
}
}
$challengeStrings = mysql_query("SELECT * FROM ChallengeStrings WHERE climbID = '$cid'") or die(mysql_error());
$output["challengeStrings"] = array();
$output["challengeVideos"] = array();
if(mysql_num_rows($challengeStrings)>0) {
$cString = array();
$challengeVideos = array();
while ($r = mysql_fetch_array($challengeStrings)) {
$cString["challengeID"] = $r["challengeID"];
$cString["challenge"] = $r["challenge"];
$cString["username"] = $r["username"];
array_push($output["challengeStrings"], $cString);
$chaID = $r["challengeID"];
$cVidResults = mysql_query("SELECT * FROM ChallengeVideos WHERE challengeID = '$chaID'") or die(mysql_error());
$challengeVideos["'$chaID'"] = array();
while ($res = mysql_fetch_array($cVidResults)) {
$video = array();
$video["challengeID"] = $res["challengeID"];
$video["videoID"] = $res["videoID"];
$video["videoURL"] = $res["videoURL"];
$video["username"] = $res["username"];
$title = $res["challengeID"];
array_push($challengeVideos["'$title'"], $video);
//array_push($output["challengeVideos"], $video);
}
}
array_push($output["challengeVideos"], $challengeVideos);
}
$output["success"] = 1; //success!
echo json_encode($output); // echoing JSON response which will be info of climb
}//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!
}
?>