EasyCFM.COM ColdFusion Forums / Tutorial Requests! / Rotating Results

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Rotating Results -- page: 1 2

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

amser
12-22-2003 @ 3:07 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 40
Joined: Dec 2003

Thanks Guy's,

The ORDER BY newID() method works fine for my home page where only 5 random results from the whole db are required.

How about if I want to show all of the results in a random order (5 per page) with next/back. What would you recommend?

Thanks Again

PS. its nice to see different views!

Confusion Expert!!!!!!!!!

CJ
12-22-2003 @ 3:16 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

i'd recommend not doing that Smile

not exactly sure what you are thinking really... next/back implies some sort of order...if they're random, there is no order.  so how would you ask for the 'next 5 random records'?  

i suppose if you wanted to pull 5 random records each time, and allow the user to travel back through each recordset...i'd probably create an array and store it in the session scope.  with each query, i'd add an element to the array...that element would contain a nested array or structure (whichever works best for you) containing the records pulled from the db.

so every position in the array would hold a nested structure with 5 records.

if the user clicks 'back', just move back 1 element in the array (you'd need to also store a session var to increment/decrement with each move forward/back, in order to know which element in the array to pull.

you sure you want to do that? Smile  



-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

amser
12-22-2003 @ 10:05 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 40
Joined: Dec 2003

Sorry to drag this one out!!! Blush

Is there some way of grabbing all the records from a table in a random order, then locking that random order so that the user can browse through all the records without encountering duplicate records along the way (and displaying 5 records per page)!?

Hmmmmm....

Confusion Expert!!!!!!!!!

CJ
12-23-2003 @ 10:09 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

you'd need to store a list of the records that have already been retrieved.  store them in a session var...let's say called session.retrieved.

<cfparam name="session.retrieved" default="">

<cfquery name="myQuery" datasource="myDSN">
    SELECT TOP 5 *
    FROM myTable
    WHERE status=1 AND recordID NOT IN (#session.retrieved#)
    ORDER BY newID()
</cfquery>

<cfset session.retrieved = listAppend(session.retrieved, valueList(myQuery.recordID))>

not tested...but that should work Smile  



-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

PAGE: 1 2

Website Designed and Developed by Pablo Varando.