I am trying to write a script that will take the returned results, compile them into an a single array and echo it to the my iOS app. Essentially I need the output to look something like this:
array[0]=dictionary
array[1]=dictionary
array[2]=dictionary
The problem I am running into is that the echo command apparently cannot be inside the while loop, so I was wondering how to compile all of the things returned in the while loop, then echo them afterwards.
This is my current code, without the contents of the while loop that I can't figure out.
<?php
require_once ('config.inc.php');
require_once (MYSQL);
// Trim all the incoming data:
$trimmed = array_map('trim', $_POST);
// Assume invalid values:
$id = FALSE;
// Check for an email address:
if ($trimmed['user_id']) {
$id = mysqli_real_escape_string ($dbc, $trimmed['user_id']);
} else {
echo "Error. No User ID submitted.";
}
if ($id) { // If everything's OK...
$q = "SELECT * FROM post LEFT JOIN users ON post.user_id = users.id WHERE users.id='$id'";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
while(mysqli_fetch_array($r,MYSQLI_ASSOC)){
/*
CODE TO COMPILE THE MULTIPLE ROWS HERE
*/
}
}
echo json_encode($multiple_row_result);
mysqli_close($dbc);
?>
Thanks in advance for all the help!