Marc,

This may be a dumb question but that's never stopped me before so,...

why the order by if you're only getting one item? and why the tickcount
part?.... what's it do?

Thanks,
Karl

> From: "Marc Campeau" <[EMAIL PROTECTED]>
> Reply-To: [EMAIL PROTECTED]
> Date: Fri, 31 May 2002 11:47:52 -0400
> To: <[EMAIL PROTECTED]>
> Subject: RE: [CFTALKTor] random selection from database
> 
> You could have done this way too. I think it would be better since you
> wouldn't be returning the whole table data just to display one row:
> 
> <cfquery name="getPhoto" datasource="dsn">
> SELECT TOP 1 items, rand(#getTickCount()#) as orderCol
> FROM db table
> ORDER BY orderCol #IIF(getTickCount() MOD 2, DE("ASC"), DE("DESC"))#
> </cfquery>
> 
> Marc Campeau
> 
>> -----Original Message-----
>> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
>> Behalf Of Graham Faulkner
>> Sent: Friday, May 31, 2002 11:23 AM
>> To: [EMAIL PROTECTED]
>> Subject: Re: [CFTALKTor] random selection from database
>> 
>> 
>> Thanks Dan.  I ended up doing the following (which seems to work
>> fine), but
>> wasn't 100% sure if it's the way you were talking about:
>> 
>> <cfquery name="getPhoto" datasource="dsn">
>> select items from db table
>> </cfquery>
>> 
>> <cfset start = 1>
>> <cfset end = getPhoto.recordcount>
>> <cfoutput query="getPhoto" startrow="#RandRange(start,end)#" maxrows="1">
>> <img src="photos/#photo#">
>> </cfoutput>
>> 
>> Blessings,
>> 
>> Graham
>> 
>> ----- Original Message -----
>> From: <[EMAIL PROTECTED]>
>> To: <[EMAIL PROTECTED]>
>> Sent: Friday, May 31, 2002 10:21 AM
>> Subject: [CFTALKTor] random selection from database
>> 
>> 
>>> You could run a query to get the min and max, then use RandRange to get
>>> your random id.  That should get you started.
>>> 
>>> *******************
>>> Hi there,
>>> 
>>> An easy one for a Friday morning...
>>> 
>>> I have a table that lists submitted photos, and would like to have a
>> random
>>> photo generator that reads from this table in the database.  What's the
>>> best
>>> way to select one random PhotoID from the table and then use it within a
>>> <cfoutput> to display a photo?
>>> 
>>> 
>>> 
>>> -
>>> You are subscribed to the CFUGToronto CFTALK ListSRV.
>>> This message has been posted by: [EMAIL PROTECTED]
>>> To Unsubscribe, Please Visit and Login to http://www.CFUGToronto.org/
>>> Manager: Kevin Towes ([EMAIL PROTECTED])
>> http://www.CFUGToronto.org/
>>> This System has been donated by Infopreneur, Inc.
>>> (http://www.infopreneur.net)
>>> 
>> 
>> -
>> You are subscribed to the CFUGToronto CFTALK ListSRV.
>> This message has been posted by: "Graham Faulkner"
>> <[EMAIL PROTECTED]>
>> To Unsubscribe, Please Visit and Login to http://www.CFUGToronto.org/
>> Manager: Kevin Towes ([EMAIL PROTECTED])
>> http://www.CFUGToronto.org/
>> This System has been donated by Infopreneur, Inc.
>> (http://www.infopreneur.net)
>> 
>> 
> 
> -
> You are subscribed to the CFUGToronto CFTALK ListSRV.
> This message has been posted by: "Marc Campeau" <[EMAIL PROTECTED]>
> To Unsubscribe, Please Visit and Login to http://www.CFUGToronto.org/
> Manager: Kevin Towes ([EMAIL PROTECTED]) http://www.CFUGToronto.org/
> This System has been donated by Infopreneur, Inc.
> (http://www.infopreneur.net)

-
You are subscribed to the CFUGToronto CFTALK ListSRV.
This message has been posted by: "A. Karl Zarudny" <[EMAIL PROTECTED]>
To Unsubscribe, Please Visit and Login to http://www.CFUGToronto.org/
Manager: Kevin Towes ([EMAIL PROTECTED]) http://www.CFUGToronto.org/
This System has been donated by Infopreneur, Inc.
(http://www.infopreneur.net)

Reply via email to