Viewer Options (Advanced: Random ?)

5 posts by 2 authors in: Forums > CMS Builder
Last Post: May 8, 2009   (RSS)

By avrom - May 8, 2009

Hi Dave, Hi Ross,

I am creating a simple detail viewer for an artist gallery template.

In the code generator, which record, viewer options, if there is no record number, then the page will always load the first record in that table.

Instead of going to the first record (if no number is at the end of the URL), can I use the ADVANCED field to set that to random ?

Screenshot attached, and thanx !! :))

Avrom
Attachments:

cms_builder_randomurl.gif 23K

Re: [virgodesign] Viewer Options (Advanced: Random ?)

By ross - May 8, 2009

Hi there.

Thanks for posting!

In your viewer code, find this line:

'where' => whereRecordNumberInUrl(1),

right above that add in:

'orderBy' => 'RAND()',

That will randomly sort your records. Technically, it actually randomly sorts even when you do have a number in your URL but there is only one record for it to randomize so it works ok. When you don't have a number, it randomly picks one from the whole list of records.

Give it a shot and let me know what you think :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] Viewer Options (Advanced: Random ?)

By avrom - May 8, 2009

Ross,

or how about just 'where' => 'RAND()',

Would that do the same thing as well ? A random record if no number in URL, but if there is a number in the URL it would grab the record number ?

Cheers and Thanx !

Re: [ross] Viewer Options (Advanced: Random ?)

By avrom - May 8, 2009

Okay got it :)) Many thanks...