php - Mysql getting json from nested queries -
i had 2 tables whch visitormaster , visitor comment. visitor master has unique visitorid , comment bt visitor stores in visitorcomment using visitorid foreign key there. want data in following format:
[ { "visitorid":1, "visitorname":"abc", "comment": { "commentid":2; "comment":"xyz" } } { "visitorid":2, "visitorname":"lmn", "comment": { "commentid":4; "comment":"mno" } } ] $sql = mysql_query("select * visitormaster"); if(mysql_num_rows($sql) > 0) { $result = array(); while($rlt = mysql_fetch_array($sql,mysql_assoc)) { $result[] = $rlt[]; $vid=$rlt["visitorid"]; $sql1 = mysql_query("select * visitorcomment visitor_id = "."'$vid'"); while($rltcomment = mysql_fetch_array($sql1,mysql_assoc)) { $commentresult[] = $rltcomment[]; } $newresult=array($result,"comment"=>$rltcomment[0]); } $array=array("result_data"=>$newresult); $this->response($this->json($array), 200); }
but there no output.
quote missing in sql statement mysql_query("select * visitormaster);
to see errors use ini_set("display_errors","on"); turn error reporting on. give errors.
Comments
Post a Comment