我们可以在 PHP 的 JSON 数组中显示像日期这样的记录吗?



我写的是:

$qry2 = $wpdb->get_results("SELECT ( SELECT guid FROM wp_posts WHERE id = m.meta_value ) AS image_url,date(p.post_date) as post_date,post_title as image_title FROM wp_posts p, wp_postmeta m WHERE p.post_type = 'image' AND p.post_status = 'publish' AND p.id = m.post_id AND p.post_title != 'Auto Draft' AND m.meta_key = '_thumbnail_id' order by p.post_date desc");

foreach($qry2 as $thumb_url){
$res_arr_value[$thumb_url->post_date][] = $thumb_url;
}
//  }
$msg= array('msg'=>'photo exist','status'=>'success','data'=>$res_arr_value);
$jsonmsg= json_encode($msg);
echo $jsonmsg;

目前我得到这样的回复:

{
"msg": "photo exist",
"status": "success",
"data": {
"2017-08-22": [
{
"image_url": "/uploads/ilse-niemann-struweg-1.jpg",
"image_title": "Image2"
},
{
"image_url": "/uploads/Teresa-Pidduck-1.jpg",
"image_title": "Test Photo2"
},
{
"image_url": "/uploads/Milagrita-Shin_Foundation.jpg",
"image_title": "Test Photo"
}
],
"2017-04-27": [
{
"image_url": "/uploads/msa-youtube.png",
"image_title": "Image"
}
]
}
}

我想像这样回应:

{ "msg": "照片存在", "状态": "成功", "数据": [ { "记录": [ { "image": "/uploads/ilse-niemann-struweg-1.jpg", "日期":"2017-08-22", "标题": "图像2" }, { "图片": "/uploads/Milagrita-Shin_Foundation.jpg", "日期":"2017-08-22", "标题": "测试照片" } ], "记录": [{ "image": "/uploads/msa-youtube.png", "日期":"2017-04-27", "标题": "图像">

} ] } ] }

谢谢,我找到了答案。如我所愿。

{ "msg": "照片存在", "状态": "成功", "数据":[{ "日期": "2017-08-25", "记录":[ { "image_url": "/uploads/for-international-students-img1.jpg", "post_date": "2017-08-25", "image_title":"测试3" }, { "image_url": "/uploads/academic-overview.jpg", "post_date": "2017-08-25", "image_title":"测试" }, { "image_url": "/uploads/source_img.jpg", "post_date": "2017-08-25", "image_title":"演示测试" } ] }, { "日期": "2017-08-22", "记录":[ { "image_url": "/uploads/Roselle-sherriff-img.jpg", "post_date": "2017-08-22", "image_title":"测试图像 2" }, { "image_url": "/上传/acb_img.png", "post_date": "2017-08-22", "image_title":"测试映像 1" } ] }, { "日期": "2017-04-27", "记录":[ { "image_url": "/上传/提供节目-1.jpg", "post_date": "2017-04-27", "image_title":"图像" } ] } ] }

最新更新