Gary: I'm sending this to you via email since CF-Talk has been so screwed up
recently.
> Thank you Phoebe, but most of the replies I have gotten do not take into
> account the deletion of a record, and hence, the broken line of sequential
> IDs.
Here's the way I would do this. I followed your approach pretty closely,
although you should note that you could increase the performance of this
code in one of two ways:
1) Select ONLY the record ID in the initial query. SELECT * will return
data for all fields in the table, none of which besides the ID is used.
There's really no sense in collecting and transferring all of this data from
the DB to CF if you aren't going to use it.
2) Alternately, you could SELECT * in the initial query (like you do
already) and then skip the final query for a specific ID value. You can
reference a specific row of a query like so: qryQuery.FieldName[RowNum]. So
if you already have all of the data you need in the query and you know the
row number you want to use you could refer to it like that rather than run a
second query. This would be very easy to add to the method I use below.
<!--- get all data --->
<cfquery datasource="application.dsn" name="records">
SELECT * FROM tblMembers
</cfquery>
<!--- get a random number between 1 and the number of records returned --->
<cfset r = RandRange(1, records.RecordCount)>
<!--- get the ID of the record at that row --->
<cfset intID = records.ID[r]>
<!--- finally, get the corresponding record --->
<cfquery datasource="application.dsn" name="finalrecord">
SELECT * FROM tblMembers WHERE ID = #intID#
</cfquery>
If you need further clarification just let me know.
Regards,
Seth Petry-Johnson
Argo Enterprise and Associates
------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.