How do I fix the following code to echo the JSON encoded array of particular rows in the SQL database table? Because all I get right now is: { "mailbox":[] }
Here is my code:
$query = "SELECT * FROM messages WHERE touser='$from'";
$result = mysql_query($query)
or die("\n\ndatabase error!\n". mysql_error());
$mailbox = array();
while($row = mysql_fetch_assoc($result)){
$mailbox[] = $row;
}
echo "{ \"mailbox\":".json_encode($mailbox)." }";