Created
September 26, 2017 02:03
-
-
Save brucenorton/dd3e3d09c5b13b877021448febd0e3b6 to your computer and use it in GitHub Desktop.
select query for request_each.json
This file contains 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 | |
require_once '../../_includes/connect.php'; | |
header('Content-type: application/json; charset=utf-8'); | |
//define table | |
$tbl = "users";//change table name as required | |
//write query | |
$query = "SELECT $tbl.userID, $tbl.userName, $tbl.userEmail, $tbl.lastSeries FROM $tbl"; | |
//prepare statement, execute, store_result | |
if($displayStmt = $mysqli->prepare($query)){ | |
$displayStmt->execute(); | |
$displayStmt->store_result(); | |
} | |
//bind results | |
$displayStmt->bind_result($userID, $userName, $userEmail, $lastSeries); | |
//create an array for the results | |
$dataArray = []; | |
$usersArray = []; | |
//fetch results | |
while($displayStmt->fetch()){ | |
//create array for json | |
$usersArray[] = ['userName' => $userName, 'userEmail' => $userEmail, 'lastSeries' => $lastSeries]; | |
//display the image | |
//echo('<div class="col-sm-4"><figure>hi<img src="uploads/files/'.$userEmail.'" class="img-fluid"><figcaption>'.$lastSeries.'</figcaption></figure></div>'); | |
} | |
//encode the array in json format | |
$dataArray["users"] = $usersArray; | |
echo( json_encode(array($dataArray))); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment