while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { array_push($data['data'], $row); } mysqli_close($conn); return $data; } $possible_url = array("get_app_list", "get_app", "get_locations", "filter_by"); $value = "An error has occurred"; if (isset($_GET["action"]) && in_array($_GET["action"], $possible_url)) { switch ($_GET["action"]) { case "get_app_list": $value = get_app_list(); break; case "get_app": if (isset($_GET["long"]) && isset($_GET["lat"])) { $value = get_app_by_id(); } else { $value = "Missing argument"; } break; case "get_locations": if (isset($_GET["loc"])) { $value = get_location_autofill($_GET["loc"]); } else { $value = "Missing argument"; } break; case "filter_by": if (isset($_GET["distance"]) && isset($_GET["service"])) { $value = get_location_autofill($_GET["loc"]); } else {
case 4: $app_info = array("app_name" => "Music Sleep Timer", "app_price" => "Free", "app_version" => "1.9"); break; } return $app_info; } function get_app_list() { //normally this info would be pulled from a database. //build JSON array $app_list = array(array("id" => 1, "name" => "Web Demo"), array("id" => 2, "name" => "Audio Countdown"), array("id" => 3, "name" => "The Tab Key"), array("id" => 4, "name" => "Music Sleep Timer")); return $app_list; } $possible_url = array("get_app_list", "get_app"); $value = "An error has occurred"; if (isset($_GET["action"]) && in_array($_GET["action"], $possible_url)) { switch ($_GET["action"]) { case "get_app_list": $value = get_app_list(); break; case "get_app": if (isset($_GET["id"])) { $value = get_app_by_id($_GET["id"]); } else { $value = "Missing argument"; } break; } } //return JSON array print json_encode($value);