That will work, as long as two conditions are met:

1) you have to know the first and last IDs in the table (solveable
with a simple min/max query preceeding the query you proposed).
2) you have to have no holes in your numbering (which is difficult to
solve with a primary key).

You'll be better off making a second key that is used strictly for
randomization (and can therefore change as needed).  Whenever a hole
develops (from a deletion) just change the highest number to whatever
number was deleted.  That way you have guarenteed that there are no
holes in the numbering scheme.

There are other ways to solve this, depending on how critical true
randomness is to your application and various other factors, but
they're all generally along these lines.

cheers,
barneyb

On Wed, 02 Mar 2005 16:34:40 -0400, Will The Game <[EMAIL PROTECTED]> wrote:
> Question: Why couldn't I use RandRange in a query to rotate a banner image? I 
> usually use JS buit it looks like a bunch of crap code. *This* would be 
> simple.
> 
> I have a tblbannerimages with ID# as PK, imagename is like image1.jpg or 
> whatever.
> 
> ID's would be 1, 2, 3, 4, 5 let's say
> 
> Now I run a query to retrieve one to output it to the banner everytime the 
> page loads.
> 
> SELECT ID, imagename
> FROM tblbannerimages
> WHERE ID = #RandRange(1,5)#
> 
> Then it goes in the banner.
> 
> <cfoutput><img src="#getimages.imagename#"></cfoutput>



-- 
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/

Got Gmail? I have 50 invites.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:197193
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to