>This s probably right under my nose but I can't see it... Here is the
>situation: I need a single item selected/displayed from a list - picked
>randomly so a single different selection (potentially) from the list shows
>each visit.
>
>-I run a query to get select records meeting some criteria.
><cfquery name="qListData" datasource="MyDB">
>SELECT ID
>FROM tblItems
>WHERE foo = 1
></cfquery>
>
>-Create a list of the IDs
><CFOUTPUT Query="qListData">
><CFSET List1 = #ListAppend(List1, ID, ",")#>
></cfoutput>
>-Order the list and pick one at random
><CFLOOP From = "1" To = "#ListLen(List1)#" INDEX = "Counter"></CFLOOP>
><CFSET Max1 = #ListLen(List1)#>
><CFSET Mselect1 = #RandRange(1, Max1)#>

Use the valueList() function intead to save some looping overhead. It does 
exactly what you're manually doing. How about trying something this instead 
of all the looping above:

<cfset list1 = valueList(qListData.id)>
<cfset mSelect1 = listGetAt( list1, randRange(1, listLen(list1)) )

The above is untested, but should get you what you want. Now, just output:

<cfoutput>#mSelect1#</cfoutput>

Regards,
Dave.

_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.  
http://join.msn.com/?page=features/featuredemail

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq

Get the mailserver that powers this list at 
http://www.coolfusion.com

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to