Nested Array to JSON in Php MySQL


I have the following data in mysql table


1 | Parent Msg | 10/10/2012| null

2 |Reponse to parent Msg| 10/10/2012| 1

3 |Response to parent msg | 10/10/2012|1

I need the nested output(multidimensional array) in JSON like this:

[Messages:[Msgid, MsgBody,Msgdate, Replies[ MsgId,MsgBody,Msgdate]]

This will output all the messages and also the replies for each message as an array.


require_once("[url removed, login to view]");

$response = array();

$messages = array();

$query="SELECT * FROM (SELECT username, userpicurl, userlocation, userbio, msgbody, msgsenddate, msgpersonal, msgparentid, msgdateposted FROM tblMsg INNER JOIN tblUser ON [url removed, login to view] = [url removed, login to view] ORDER BY MsgId DESC LIMIT 0 , 10) AS tbl ORDER BY [url removed, login to view]";

$result = mysql_query($query,$con) or die('Errant query: '.$query);



$username =$row['username'];

$picurl =$row['userpicurl'];


$messages[] = array('username'=> $username,'picurl'=>$picurl,'location'=>$location,'bio'=>$bio, 'msgbody'=> $msgbody,'senddate'=>$senddate,'personal'=>$personal,'receiverid'=>$receiverid); }

$response['messages'] = $messages;



Skills: MySQL, PHP, Software Architecture, Software Testing, User Interface / IA, Web Hosting, Website Management, Website Testing

See more: nested array json php, nested result mysql json, multidimensional data, php json mysql nested array, php json, json, json php, json c, json and mysql, php mysql join table, mysql join table, mysql table join, php table array, nested, php nested, personal bio, php response json, json response php, json response, mysql output table, tbl, php json mysql table, php json output, nested query, php output json

Project ID: #2772977

2 freelancers are bidding on average $15 for this job


See private message.

$12 USD in 14 days
(52 Reviews)

See private message.

$17 USD in 14 days
(6 Reviews)