ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 11th, 2003, 11:47 AM
jrockfl jrockfl is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 11 jrockfl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Random image display with ASP

I'm storing the image name in the db. I'd like to query a random image and display it on the page....I can do it in CF, but I need to do this in ASP. Here is how it is done in CF

<cfquery name="randompicture" datasource="#dsn#">
SELECT image
FROM gallery
</cfquery>

<cfset random_row = RandRange(1, randompicture.recordcount)>

<!--- Output Image --->

<cfoutput>
<img src="images/#randompicture.image[random_row]#">
</cfoutput>

Reply With Quote
  #2  
Old March 11th, 2003, 06:47 PM
aspnewbie aspnewbie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: The Great White North
Posts: 361 aspnewbie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 50 sec
Reputation Power: 7
Send a message via MSN to aspnewbie

Reply With Quote
  #3  
Old March 12th, 2003, 06:47 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
If you're using sequential primary keys, simply do a random number generation algorithm to get a number, then perform a select using that key id.
Code:
randomize
varRandNum = cint((idx ) * Rnd + 1)
i use this code to randomly select an image off the filesytem, to be used as a background on my personal site

Reply With Quote
  #4  
Old March 12th, 2003, 07:05 AM
Stragulpete Stragulpete is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 5 Stragulpete User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Here is a simple script I use for this purpose. It does not require any database query or recordset. Just place your random images in one folder, name them sequentially (randImg_1.jpg, randImg_2.jpg ...) and the script will do the rest:

<%
Const NUMBER_OF_IMAGES = n
Randomize
Dim intImageNumber
intImageNumber = Int((NUMBER_OF_IMAGES * Rnd) + 1)
%>

Replace 'n' with number of images in the foldert, update this number when you add new images.

And the link to the images should be:

<IMG SRC="RandomImagesFolder/randImg_<%= intImageNumber %>.jpg">

Good luck
Maurice

Reply With Quote
  #5  
Old March 12th, 2003, 07:12 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Looks identical to my code... lol

Reply With Quote
  #6  
Old March 12th, 2003, 07:50 AM
jrockfl jrockfl is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 11 jrockfl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thank you!

thank you everyone! I will give it a try

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > Random image display with ASP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway