i am not sure about the order database, but i think it doesn't work in MSSQL
since Rand function always return the same value in all rows in one query.

for MS SQL 2000, u can try using the NewID():

<cfquery name="getPhoto" datasource="dsn">
    SELECT TOP 1 items, NewID() as orderCol
    FROM db table
    ORDER BY orderCol #IIF(getTickCount() MOD 2, DE("ASC"), DE("DESC"))#
</cfquery>


rgds,

=============================
Mike Lau
Web Developer

[EMAIL PROTECTED]
User In Mind Creative Group Inc.

http://www.userinmind.com
Toll Free: 1-866-294-6644
T: (416) 490-7556
F: (416) 490-6889
=============================

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of Marc Campeau
Sent: Friday, May 31, 2002 11:48 AM
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: "Mike Lau" <[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