I have a table with many records. I just want to display a random record on page load and I can't figure out how to do it.
I am sure I have done this before and it should be very simple. I jsut can't see it.
Any hints would be welcomed. Thanks.
I have a table with many records. I just want to display a random record on page load and I can't figure out how to do it.
I am sure I have done this before and it should be very simple. I jsut can't see it.
Any hints would be welcomed. Thanks.
I always use a custom query with LIMIT 1 and ORDER BY RND()
But there is also the randomise() function within collections to randomise the data then use element [0]
Thank you Brian! You gave me a hint. I had to make my query a regular query instead of a single query.
Works like a charm using the randomize formatter.
You will find the custom query option more efficient as only a single record is returned from server connect so less data and no need to .randomize() but only a real concern if you are using big data sets.
Adding the top(1) formatter on a repeat region works wonderfully. Again, thanks for indirectly pointing me in. the right direction. It's working perfect.
I think a custom query would be more efficient but I am not comfortable with my custom query skills.
I also do the same sometimes
You can convert a normal query into a custom one so the main work is done for you. Then just add the ORDER BY
to it.