Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
$query="select id,title,description,url,votes from posts order by id desc";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$arr = array();
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$arr[] = $row;
# JSON-encode the response
$json_response = json_encode($arr);
// # Return the response
echo $json_response;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment