Combined listing pages into one page in date order
12 posts by 3 authors in: Forums > CMS Builder
Last Post: May 2, 2016 (RSS)
By TheSeen - February 3, 2016
Hi all ...
What is the easiest way to combine lists and display them in date order?
For example I want the lists from sections: Cinema, Live and Exhibitions to be displayed together in a single page (What's On) and displayed in a single list in date order of the event.
Cheers
By Steve99 - February 3, 2016
Hello,
This example should help get you started. Do your getRecords calls as you normally would, then do an array merge, then use this function with usort for date sort.
<?php
function cmp($a, $b){
$ad = strtotime($a['date']);
$bd = strtotime($b['date']);
return ($bd-$ad);
}
$recordsMerged = array_merge($cinemaRecords, $liveRecords, $exhibitRecords); // merge arrays
usort($recordsMerged, 'cmp'); // sort articles by date
?>
<?php // output ?>
<?php foreach ($recordsMerged as $index => $record): ?>
Record Info Here
<?php endif ?>
Cheers,
Steve
By Steve99 - April 27, 2016
Hi Adrian,
On your new page that will combine and list from both sections, place the function in the top of your page. Then place each of your standard listing getRecords calls as you normally would.
<?php
function cmp($a, $b){
$ad = strtotime($a['date']);
$bd = strtotime($b['date']);
return ($bd-$ad);
}
// load your records from the "whats on" and "live events" tables
// load records from 'yourtable_listings'
list($yourtable_listingsRecords, $yourtable_listingsMetaData) = getRecords(array(
'tableName' => 'yourtable_listings',
'loadUploads' => true,
'allowSearch' => false,
));
// load records from 'yourtable2_listings'
list($yourtable2_listingsRecords, $yourtable2_listingsMetaData) = getRecords(array(
'tableName' => 'yourtable2_listings',
'loadUploads' => true,
'allowSearch' => false,
));
// merge the arrays returned from each getRecords call
$recordsMerged = array_merge($yourtable_listingsRecords, $yourtable2_listingsRecords); // merge arrays
usort($recordsMerged, 'cmp'); // sort articles by date
?>
Then in the body, place your foreach loop to display:
<?php foreach ($recordsMerged as $index => $record): ?>
Record Info Here
<?php endif ?>
Hope this helps.
Cheers,
Steve
By Steve99 - April 27, 2016
Great, glad it's working for you!
You can set "Order By" on both of those Section Editors in the CMS under the Sorting tab to date DESC. By default the CMS will sort your records by what is set in there. Best way to handle it.
The sorting can also be manipulated on the getRecords array:
'orderBy' => 'set your sorting here',
Cheers,
Steve
By TheSeen - April 27, 2016
Hi Steve ...
Updated the CMS to 'date DESC, title' but it's putting all events into backward order both on website and in the cms
i.e.. not the nearest date first
The main combined index page is still backward order too.
In the CMS when it was set to 'date, title' the events were all ordered listed correctly in the cms and on website pages (apart from the combined index page).
By Steve99 - April 27, 2016
My apologies, I read that too fast! Instead of DESC you'll want to use ASC, so it will be 'date ASC'. You should be good to go after that.
Cheers,
Steve
By TheSeen - April 27, 2016
Thanks Steve ...
Will try this as soon as possible.
I've lost all access into an site cms pages or to the cms itself though. Getting the flooding error message from the cms:
The database error given was:
User update already has more than 'max_user_connections' active connections
Any ideas what this could be? Any one possibly messing around after I put the urls on the forum?
By Damon - April 27, 2016
I emailed you directly b\ut wanted to post here as well for anyone else with the same issue.
If you are getting a database down message, check with the host to see if they are experiencing server issues.
Dave posted a stand alone script that does nothing but try to connect to the database. You can find it here:
https://www.interactivetools.com/forum/forum-posts.php?postNum=2237814#post2237814
Just enter your own database details and upload it to your site. Then if you are still getting the message that the database server is down, run the script to confirm.
Then you can send the host a link to the script and ask them why the server is down.
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/