There are many ways to do this. Here's one:
<!-- begin index_pick_a_partner_at_random.cfm -->
<!--- get the max record id from the table --->
<cfquery name="max" datasource="#session.dsn#">
SELECT max (CONTACT_ID) as maxid
FROM CONTACTS
</cfquery>
<!--- set a random number --->
<cfset randnum = RandRange(1,max.maxid)>
<!--- Then select the a record where the recordid equal to or greater than the random
number. --->
<cfquery name="random_record" datasource="#session.dsn#">
SELECT MIN (CONTACT_ID) as random_record
FROM contacts
where CONTACT_ID >= #randnum#
</cfquery>
<cfoutput query="random_record">
#random_record#
</cfoutput>
<!-- end index_pick_a_partner_at_random.cfm -->
---mark
--------------------------------------------------------------
Mark Warrick
Phone: (714) 547-5386
Fax: (714) 972-2181
Personal Email: [EMAIL PROTECTED]
Personal URL: http://www.warrick.net
Business Email: [EMAIL PROTECTED]
Business URL: http://www.fusioneers.com
ICQ: 346566
--------------------------------------------------------------
> -----Original Message-----
> From: Jeremy Bunton [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, January 16, 2001 1:32 PM
> To: CF-Talk
> Subject: random record
>
>
> Can anyone point me in the right direction regarding how I would go about
> pulling a random record from a table every time a user visits the page.
>
> JLB
>
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists