carcam wrote: ↑Tue Oct 04, 2022 1:07 pm
I'm not sure if I understand your problem completely.
I think you want to be able to group your elements in the SQL query. You can use the ->group() method of the Query Class to do that. I do not remember the syntax exactly but it should be something like:
$ob->select('*')
->from($db->quoteName('#__content'))
->where("`catid` = '15'")
->group(FIELD)
I'm not sure if you are allowed to group a MySQL query with a calculated field, but if you are, that will work.
Another possibility is to use the ArrrayHelper class on the results to group them by the specific key.
Thank you but nop...
Your first query has to have all that you need with all the information and filters except for grouping, why not grouping, well, you can't foreach() the results and grouping on the first query means that you have to make another query for details...
Code: Select all
$query = [
[
'id'=>12,
'title'=>'Article 1'
'created'=>'2001-03-05'
],
[
'id'=>12,
'title'=>'Article 1'
'created'=>'2001-05-03'
],
[
'id'=>12,
'title'=>'Article 1'
'created'=>'2004-03-03'
],
[
'id'=>12,
'title'=>'Article 1'
'created'=>'2005-03-05'
]
]
Say that the first query give you an array like that, then you need a "filter" by year in order to build your list.
Code: Select all
<ul>
<li><a href="#" data-filter-year="2001">2001</a></li>
<li><a href="#" data-filter-year="2004">2004</a></li>
<li><a href="#" data-filter-year="2005">2005</a></li>
</ul>
To build "filter" based on the first query you need a foreach() and a temporary array so you don't repeat the information, then you need a count() in order to build a pagination.
that is just one filter of a few, you have to foreach() the same query for as many filters.
The idea is that the first query be able to be use as a "second" query or third or as many....
Code: Select all
$rawData = $db->loadObjectList();
$years = $rawData->load()->group('created');
$special = $rawData->load()->group('special');
$cats = $rawData->load()->group('catid');
In laravel we use something similar, single query then we just work with that, reorder, grouping without making more calls.
Nothing for the moment....