【问题标题】:Get distinct dates from json array joomla从 json 数组 joomla 中获取不同的日期
【发布时间】:2013-02-07 01:17:23
【问题描述】:

我的组件将 json 数组保存在数据库中:

所以我想从所有字段中获取不同的日期。

数据库字段包含这样的值:

a:3:{i:0;s:16:"2013-02-24 00:00";i:1;s:16:"2013-02-23 00:00";i:2; s:16:"2013-02-22 00:00";}

【问题讨论】:

    标签: joomla joomla2.5


    【解决方案1】:

    您所拥有的是序列化数据,而不是 json 编码。我不相信有一种方法可以使用 mysql 查询仅从数据库中获取日期(因此大多数人建议您不要以序列化甚至 json 形式存储数据)。

    您可能希望从数据库中获取数据(使用 $query 变量是您需要从数据库中获取数据的查询。由于我不知道您的数据库是什么样的,所以我不会去编写查询)

    $rows = JFactory::getDbo()->setQuery($query)->loadObjectList();
    
    foreach ($rows as $row) {
        $dates = unserialize($row->date_column);
        // do something with the $dates variable, which is now an array of the three dates.
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-19
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 2021-11-20
      • 2013-11-05
      • 1970-01-01
      相关资源
      最近更新 更多