php mysql json document makeup -


i'm using of code generate json data form mysql table :

$sql = "select * u3d15"; $result = mysql_query($sql); $json = array(); if(mysql_num_rows($result)){     while($row=mysql_fetch_row($result)){         $json['title'][]=$row;     } } mysql_close($db_name); echo json_encode($json);  

but json looks like: {"title":[["1","kevin","t0e0gaa"]]}

i be:

{    "title" : "decode json",    "id" : 20,    "buttons" :    [      {        "title" : "kevin ",        "image" : "t0e0gaa"      },      {        "title" : "lora ",        "image" : "v1awyqr"      }    ] } 

how can change makeup of file?

setup array formatted results.

$json = array(); //create empty array $json["title"] = "decode json"; $json["id"] = 20; $json["buttons"] = array(); //empty nested array - fill mysql results  $sql = "select * u3d15"; $result = mysql_query($sql); if(mysql_num_rows($result)){     while($row=mysql_fetch_row($result)){         $json["buttons"][]=$row; //insert mysql rows buttons array     } } mysql_close($db_name); echo json_encode($json);  

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -