Hi
I am trying to read the datas from mysql using php in json. but i am not getting my expected output. Please help me to fix the issue.
code
<?php
include('../config.php');
//mysql_query("SET NAMES 'utf8'");
$tdate = date('d-m-Y');
$url = 'url';
$sql = "SELECT * FROM pimage where date<='$tdate' and pstatus='Y' ORDER BY id desc";
$result = mysql_query($sql,$conn);
$array = array("photoOfDayList"=>array());
while($row = mysql_fetch_array($result ))
{
$b = array();
$a = array("photoOfDay"=>array());
$a["photoTitle"] = $row['ptitle'];
$a["photoId"] = $row['id'];
$a["date"] = $row['date'];
$a["thumbImg_Phone"] = 'url'.$row['pimage'];
$a["thumbImg_Tablet"] = 'url'.$row['pimage'];
$a["img_Phone"] = 'url'.$row['pimage'];
$a["img_Tablet"] = 'url'.$row['pimage'];
$array["photoOfDay"][] = $a;
$array["photoOfDayList"][] = $b;
}
header("Content-type: application/json; charset=utf-8");
echo json_encode($array);
exit();
?>
I am getting a below Output
{
"photoOfDayList": [
[],
[],
[]
],
"photoOfDay": [
{
"photoOfDay": [],
"photoTitle": "Title",
"photoId": id,
"dateTime": "date",
"thumbImg_Phone": "$url/photo.jpg",
"thumbImg_Tablet": "$url/photo.jpg",
"img_Phone": "$url/photo.jpg",
"img_Tablet": "$url/photo.jpg"
},
{
"photoOfDay": [],
"photoTitle": "Title",
"photoId": id,
"dateTime": "date",
"thumbImg_Phone": "$url/photo.jpg",
"thumbImg_Tablet": "$url/photo.jpg",
"img_Phone": "$url/photo.jpg",
"img_Tablet": "$url/photo.jpg"
},
......
{
"photoOfDay": [],
"photoTitle": "Title",
"photoId": id,
"dateTime": "date",
"thumbImg_Phone": "$url/photo.jpg",
"thumbImg_Tablet": "$url/photo.jpg",
"img_Phone": "$url/photo.jpg",
"img_Tablet": "$url/photo.jpg"
}
]
}
My expected Output should be
{
"photoOfDayList": [
{
"photoOfDay": {
"photoTitle": "Title",
"photoId": id,
"dateTime": "date",
"thumbImg_Phone": "$url/photo.jpg",
"thumbImg_Tablet": "$url/photo.jpg",
"img_Phone": "$url/photo.jpg",
"img_Tablet": "$url/photo.jpg"
},
{
"photoTitle": "Title",
"photoId": id,
"dateTime": "date",
"thumbImg_Phone": "$url/photo.jpg",
"thumbImg_Tablet": "$url/photo.jpg",
"img_Phone": "$url/photo.jpg",
"img_Tablet": "$url/photo.jpg"
},
.
.
.
.
{
"photoTitle": "Title",
"photoId": id,
"dateTime": "date",
"thumbImg_Phone": "$url/photo.jpg",
"thumbImg_Tablet": "$url/photo.jpg",
"img_Phone": "$url/photo.jpg",
"img_Tablet": "$url/photo.jpg"
}
}
],
"code": 0,
"result": "success"
}