php - Associative array to Json -


i able generate json output in following format:

{"a":{"ax":1,"abx":2},"b":{"bax":1,"bbx":2},"c":3,"d":4,"e":5} 

although have found respective code this:

$arr = array('a' => array('ax' => 1, 'abx' => 2), 'b' => array('bax' => 1, 'bbx' => 2), 'c' => 3, 'd' => 4, 'e' => 5); 

, i'm struggling generate output using data sql query. have tried array_push() , array_merge() , closest have managed this:

[{"a":{"ax":1,"abx":2}},{"b":{"bax":1,"bbx":2}}, ....] 

any ideas?

first should query data table , move array, after this,use json_encode($array) function.

place array inside parameters.

then output bee in json form.

$query="select *  employees"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) {   $employee=$row['employee'];    $country=$row['country'];    $employees[] = array('employee'=> $employee,'country'=> $country); }  echo $jsonformat=json_encode($employees); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -