Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
select query for request_each.json
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)){
//bind results
$displayStmt->bind_result($userID, $userName, $userEmail, $lastSeries);
//create an array for the results
$dataArray = [];
$usersArray = [];
//fetch results
//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