php - I want to send json response of my select query two in one -
php - I want to send json response of my select query two in one -
header('content-type: application/json'); include("con.php"); $school_id=1; $sql=mysql_query("select * tbl_photogallery school_id=$school_id"); $response=array(); $info=array(); while($rows=mysql_fetch_assoc($sql)){ $galleryinfo=array(); $galleryinfo["image_name"]=$rows["image_name"]; $galleryinfo["image_url"]=$rows["image_url"]; array_push($info,$galleryinfo); } $response["school_id"]=$school_id; $response['info']=$info; echo json_encode($response);
here getting 1 1 row in json response want 2 database row in 1 photo gallery here below mention output , format of response want
my output giving me output in manner.
{ "sucesss": "1", "school_id": 1, "info": [ { "image_name": "school1.jpg", "image_url": "http://mydomain.in/mobi_school/photogallery/school1.jpg" }, { "image_name": "school2.jpg", "image_url": "http://mydomain.in/mobi_school/photogallery/school2.jpg" } ] } i want response of json in manner can show response 2 images in row.
{ "sucesss": "1", "school_id": 1, "info": [ [ { "image_name1": "school1.jpg", "image_url1": "http: //geetaarts.in/mobi_school/photogallery/school1.jpg", "image_name2": "school1.jpg", "image_url2": "http: //geetaarts.in/mobi_school/photogallery/school1.jpg" } ] ] }
try this
header('content-type: application/json'); include("con.php"); $school_id=1; $sql=mysql_query("select * tbl_photogallery school_id=$school_id"); $response=array(); $info=array(); $info_arr=array(); while($rows=mysql_fetch_assoc($sql)){ $galleryinfo=array(); $galleryinfo["image_name"]=$rows["image_name"]; $galleryinfo["image_url"]=$rows["image_url"]; array_push($info_arr,$galleryinfo); } array_push($info,$info_arr); $response["school_id"]=$school_id; $response['info']=$info; echo json_encode($response); php json
Comments
Post a Comment