I need to build an array of arrays from data pulled from my MySQL database.
After that, I need to use the json_encode function on it.
I have code below that I've been scratching my head over for days.
It seems like it should be simple enough, but I can't figure out how to properly
generate this. I keep getting an "Unexpected T_WHILE" error where the while loop
is below.
I can get it to work if it's all static, but I can't figure out how to get it to work while
drawing a variable number of rows from the database.
// The script needs to return an array of arrays encoded in JSON format
$resource = mysql_query("-- insert query here");
echo json_encode(
array(
while($result = mysql_fetch_array($resource))
{
array(
'foo' => $result["foo"],
'bar' => $result["bar"],
'fooey' => $result["fooey"],
);
}
));
Thanks in advance for any help at all!