【问题标题】:can we show the records like date wise in json array in php?我们可以在 php 的 json 数组中显示日期之类的记录吗?
【发布时间】:2018-02-05 07:25:31
【问题描述】:

我曾这样写:

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

【问题讨论】:

  • 你想达到什么目的?
  • 是原始数据还是预期输出?您需要向我们提供所有信息。原始数据、预期输出您自己解决的尝试。这个问题目前非常不清楚。
  • @MagnusEriksson ,这是预期的结果。
  • 请阅读我的评论。我们没有足够的信息来帮助您。您还需要自己进行一些尝试。 SO 不是免费的编码服务。
  • 您需要弄清楚预期的输出实际上应该是什么样子。您问题中的当前格式是 invalidimpossible

标签: php json wordpress


【解决方案1】:

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

{ "msg": "照片存在", “状态”:“成功”, “数据”: [{ “日期”:“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": "演示测试" } ] }, { “日期”:“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" } ] }, { “日期”:“2017-04-27”, “记录”: [ { "image_url": "/uploads/programmes-offered-1.jpg", "post_date": "2017-04-27", "image_title": "图片" } ] } ] }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多