Limit to 3 in a specific section only & using RAND
6 posts by 3 authors in: Forums > CMS Builder
Last Post: May 22, 2016 (RSS)
By degreesnorth - May 19, 2016
Hi Anyone
Is there a way to limit to 3 for a certain section only? I am using the same table for a list on one section of the page where I need to display all of the listings, and in another area on the page, limit the display to only 3 and randomly.
If I use
'limit' => '3',
then it affects the first section where I don't want them limited but solves the 2nd section (not what I want) and if I use
'orderBy' => 'RAND()',
it orders them randomly which I want for the 2nd section, but I actually want the first area on the page when I am using this table to be sorted as editor.
Any suggestions please?
Thanks in advance.
By Deborah - May 20, 2016
Hi, degreesnorth.
This is what I usually do when I need to display different views of a list section the same page.
// load records from 'blog'
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'loadUploads' => true,
'allowSearch' => false,
));
// load records from 'blog'
list($blogRecordsRANDOM3, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'limit' => '3',
'orderBy' => 'RAND()',
'loadUploads' => true,
'allowSearch' => false,
));
<?php foreach ($blogRecords as $record): ?>
shows all records in the order set in CMS
<?php endforeach ?>
<?php foreach ($blogRecordsRANDOM3 as $record): ?>
shows 3 random records
<?php endforeach ?>
~ Deborah
By Damon - May 20, 2016
Hi Deborah,
Your code is right. I tested it and I get the results that you are after.
All the records sorted by date and then three random records.
Can you attach your whole php page and include the URL to where you have this set up?
Or send the details into support@interactivetools.com.
Thanks!
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
By Deborah - May 20, 2016
Hi, Damon. I was posting a potential solution for degreesnorth, not asking a question. (Just in case you think I'm needing assistance.)
But, thanks anyway!
Deborah
By Damon - May 20, 2016
Hi Deborah,
Whoops. I was reading the thread too quickly. Thought you had posted twice, issue and possible solution.
Thanks for sharing your code!
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
By degreesnorth - May 22, 2016
Hi Deborah
Thank you so much. Works like a dream and one incredibly useful string of code.
Really appreciate your time to contribute back to me.
Thanks again.
Cheers
Carole