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)

Re: [zaba] limit to first 6 records not working with order by rand()

By Jason - July 12, 2011

Hi,

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

Do you have to put in an orderby clause if you are using the same order as the editor?

Re: [zaba] limit to first 6 records not working with order by rand()

By Jason - July 12, 2011

Hi,

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

Thanks,
works perfectly!