Hi Karl,

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

Never a dumb question, it usually is unclear/absent explanations.

1) why the order by if you're only getting one item?
The order by is there to sort the result set by the random column ensuring
that the 1st row is actually not the first one found in the DB but the first
random one. Without the order by the select would probably return the same
1st row for every call.


2) why the tickcount part?.... what's it do?
Well, the rand function needs a seed to initialize and ususally it is better
to use a different number every time you initialize the function other wise
the function yields the same random series, hence the use of getTickCount().
Now, as Mike showed, in this case it isn't usefull as the function is called
on a per row basis on Select using the same tickCount, so using an unique
integer column on the given table gives a different seed to the rand
function ensuring a different random series for every call of the function.


Hope this is clearer...

Marc

>
> > 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)


-
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)

Reply via email to