Posts Tagged "json_encode"

Passing Json Format from PHP to ExtJS

August 22nd, 2010 by aditia rahman / No Comments  

     

When I wrote my previous post, there are some function in PHP that sent the output as Json format to be used in JsonStore component, sometimes I create the json format manually with string concatenation, looping through the data, this is quite simple actually, but I write this post because when I got an error from this json format, it make me feel a bit dizzy  for example:

$query = $this->db->get('products');
$json = "{'products':[";
foreach($query->result() as $data)
{
	$json .= '{"id":"'.$data->id.'",
				"name":"'.$data->name.'",
				"price":"'.$data->price.'",
				"image":"'.$data->image.'"},';
}
$json .= "]}";
echo $json;