Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
select query for request_each.json
<?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