Just populate an array first?
include("connect.php");
$q = mysql_query("SELECT * FROM tbl1");
$rs = array();
while($r=mysql_fetch_array($q)) {
$rs[] = $r;
}
foreach ($rs as $r) {
//do stuff
}
By the way it looks like you're piecing together a JSON string by yourself, and then json_encode
'ing it afterwards... Just make the array and then let json_encode
do the encoding. Ie. json_encode($rs);