|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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> |
|
#2
|
|||
|
|||
|
|
|
#3
|
||||
|
||||
|
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) |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
||||
|
||||
|
Looks identical to my code... lol
|
|
#6
|
|||
|
|||
|
thank you!
thank you everyone! I will give it a try
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > ASP Development > Random image display with ASP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|