limit to first 6 records not working with order by rand()
5 posts by 2 authors in: Forums > CMS Builder
Last Post: July 12, 2011 (RSS)
By zaba - July 12, 2011
is there anything I can do here?
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'allowSearch' => '0',
'limit' => '6',
'orderBy' => 'RAND()',
));
Re: [zaba] limit to first 6 records not working with order by rand()
By Jason - July 12, 2011
What you need to do is return 6 records in their normal order and then randomize them using the shuffle() function.
For example, if you wanted to get the 6 newest news records in a random order, you can do this:
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'allowSearch' => '0',
'limit' => '6',
'orderBy' => "createdDate DESC",
));
shuffle($newsRecords);
You can now output $newsRecords normally.
Hope this helps
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] limit to first 6 records not working with order by rand()
By zaba - July 12, 2011
Re: [zaba] limit to first 6 records not working with order by rand()
By Jason - July 12, 2011
orderBy is optional, so you don't have to include it if you just want to use the the ordering that's in the editor.
Hope this helps
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] limit to first 6 records not working with order by rand()
By zaba - July 12, 2011
works perfectly!