Arrays within arrays
Posted: Wed May 13, 2009 5:25 pm
Hey guys,
I'm trying 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 so I can pass it to a JavaScript script.
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.
Thanks in advance for any help at all!
I'm trying 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 so I can pass it to a JavaScript script.
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.
Code: Select all
// 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"],
);
}
));