I want to get json with php encode function like the following
Here is a solution that i came with
$i = 1;
$array = array();
while($row = mysql_fetch_array($result))
{
$array[] = json_encode(array('id'=>$i, 'name' => $row['name']));
$i++;
}
echo implode(',', $array); // Take output array glue it with the
This will put the json into an array and then implode it with glue (,) outputing the following {"results":[{"id":1,"name":"maadi"},{"id":2,"name":"monofiya"}]} without the need to do the array first then pass it to the json_encode() function