Search code examples
joomlajoomla2.5

Get distinct dates from json array joomla


My component saves json array in database :

so i want to get distinct dates from all the fields.

database field contains values like this :

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";}


Solution

  • What you have there is serialized data, not json encoded. I don't believe there is a way to grab just the dates out of the database using a mysql query (hence most people recommending that you don't store data in a serialized or even a json form).

    You would want to grab the data from the database maybe like so (with the $query variable being the query you need to get data from the database. Since I have no idea what your database looks like, I'm not going to write the 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.
    }