Being lazy and not fishing out my sql ref's - how does the newID() work? I think this could reduce some of my code dramatically!!
mike -----Original Message----- From: Taco Fleur [mailto:[EMAIL PROTECTED] Sent: Thursday, 29 September 2005 3:47 p.m. To: CF-Talk Subject: RE: Every once in a while, I feel smart. A story of displaying a single random image. Hmm, sorry to break your bubbles but both solutions are very inefficient. The best thing to do is (in MS SQL) SELECT TOP 1 * FROM yourTable ORDER BY NEWID() That will give you a random record every time and you are not transferring a whole record set over the network. Have fun ;-) Taco Fleur - Pacific Fox an industry leader with commercial IT experience since 1994 . http://www.pacificfox.com - Web Design and Development > -----Original Message----- > From: Jim Davis [mailto:[EMAIL PROTECTED] > Sent: Thursday, 29 September 2005 1:29 PM > To: CF-Talk > Subject: RE: Every once in a while, I feel smart. A story of > displaying a single random image. > > > > -----Original Message----- > > From: Pete Ruckelshaus [mailto:[EMAIL PROTECTED] > > Sent: Wednesday, September 28, 2005 11:11 PM > > To: CF-Talk > > Subject: Every once in a while, I feel smart. A story of > displaying a > > single random image. > > > > I thought I'd share this simple solution that I came up with. > > Great idea - nothing like some brain fuel. ;^) > > > I'm building a site that has a photo album as part of it. > The image > > data (caption, description, filename, etc.) is stored in a > SQL Server > > database and the image is on the server file system. > > > > <cfset randImgRow = randRange(1, getRandImage.recordcount)> > > > > Finally, and here's where the dead-simple beauty of all > this comes in, > > display the random image using cfloop's startrow and endrow > using the > > randImgRow value: > > > > <cfoutput><cfloop query="getRandImage" startrow="#randImgRow#" > > endrow="#randImgRow#"><a > > href="/album/default.cfm?albumid=#getrandimage.album_id#"><img > > src="/images/album/#getRandImage.thumbnail#" > > alt="#getRandImage.caption#" > > class="thumbnail"></a></cfloop></cfoutput> > > Just to be a jerk however... > > You don't actually need the loop at all. Remember that you > can access a query using indexed notation - so the above > could be written as: > > <cfset randImgRow = randRange(1, getRandImage.recordcount)> > <cfoutput><a > href="/album/default.cfm?albumid=#getrandimage.album_id[randIm > gRow]#"><img > src="/images/album/#getRandImage.thumbnail[randImgRow]#" > alt="#getRandImage.caption[randImgRow]#" > class="thumbnail"></a></cfoutput> > > Of course both solutions do the exact same thing and both > access the query... I wouldn't be surprised to find them both > about the same performance-wise as well. Mine is really just > a little less code. > > I cover this in more details in my "Guide to CFML Variables" here: > http://www.depressedpress.com/Content/Development/ColdFusion/Guides/Vari able s/NotationIndexed.cfm Don't get me wrong tho' - I agree completely about "informational" posts like this. I wish more people would throw up snippets when they get something to work. ;^) Jim Davis ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Discover CFTicket - The leading ColdFusion Help Desk and Trouble Ticket application http://www.houseoffusion.com/banners/view.cfm?bannerid=48 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:219559 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

