我们可以在php中的json数组中显示日期明智的记录吗?

时间:2017-08-28 04:57:03

标签: php json wordpress

我写得像:

$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年8月22日”, “标题”:“Image2” },  {“image”:“/ uploads / Milagrita-Shin_Foundation.jpg”,  “日期”:“2017年8月22日”, “标题”:“测试照片”} ] “记录”:  [{“image”:“/ uploads / msa-youtube.png”, “日期”:“2017年4月27日”, “title”:“Image”}]}]}

1 个答案:

答案 0 :(得分:0)

谢谢,我找到了答案。我想要。

{" msg":"照片存在",     "状态":"成功",     "数据":[{             " date":" 2017-08-25",             "记录":[                 {                     " image_url":" /uploads/for-international-students-img1.jpg",                     " post_date":" 2017-08-25",                     " image_title":" Test3"                 },                 {                     " 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":"演示测试"                 }             ]         },         {             " date":" 2017-08-22",             "记录":[                 {                     " image_url":" /uploads/roselle-sherriff-img.jpg",                     " post_date":" 2017-08-22",                     " image_title":"测试Image2"                 },                 {                     " image_url":" /uploads/acb_img.png",                     " post_date":" 2017-08-22",                     " image_title":"测试Image1"                 }             ]         },         {             " date":" 2017-04-27",             "记录":[                 {                     " image_url":" /uploads/programmes-offered-1.jpg",                     " post_date":" 2017-04-27",                     " image_title":"图像"                 }             ]         }     ] }