Last active
December 14, 2015 06:09
-
-
Save anthonycvella/5040864 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function game() { | |
global $db; | |
if ($_SERVER['REQUEST_METHOD'] == "POST") { | |
$userID = isset( $_POST['userID'] ) ? $_POST['userID'] : false ; | |
if ( !$userID ) { | |
header('Content-type: application/json'); | |
echo json_encode(array( | |
'userID' => $userID, | |
'message' => 'Game data pull failed' | |
)); | |
return false; | |
} | |
// Gets the School ID based on the User ID | |
$db->query("SELECT schoolID FROM schools WHERE `schoolAdmin` = ?")->bind(1, $userID)->execute(); | |
if ($db->getTotalRows()) { | |
$result = $db->fetch(); | |
$schoolID = $result['schoolID']; | |
} | |
$db->query("SELECT * FROM games WHERE `homeSchoolID` = ?")->bind(1, $schoolID)->execute(); | |
if ($db->getTotalRows()) { | |
$result = $db->fetchAll(); | |
} | |
if (isset($result)) { | |
header('Content-type: application/json'); | |
echo json_encode(array( | |
'result' => $result, | |
)); | |
return true; | |
} else { | |
header('Content-type: application/json'); | |
echo json_encode(array( | |
'message' => 'Failed' | |
)); | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment