Skip to content

Instantly share code, notes, and snippets.

@anthonycvella
Last active December 14, 2015 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonycvella/5040864 to your computer and use it in GitHub Desktop.
Save anthonycvella/5040864 to your computer and use it in GitHub Desktop.
<?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