By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,786 Members | 2,241 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,786 IT Pros & Developers. It's quick & easy.

select next database field rather than random

100+
P: 229
Hi, I have this code to randomly select an image from a sequence of fields in my database. Does anyone know if rather than random, one could simply move from one field to the next sequentialy. That would stop the problem of it randomly selecting the same field twice? The idea is that on page refresh the next pic is selected. It works a treat randomly.

I have been told its not possible as how does the webpage remember what the last pic was!


Expand|Select|Wrap|Line Numbers
  1.     <%  
  2.     If Not rsCard.EOF Then
  3.     rsCard.AbsolutePage = intPage 
  4.  
  5.  
  6.    For intRecord = 1 To rsCard.PageSize
  7.     CurrentColumn=1
  8. %>
  9. <tr>     
  10.  
  11.  
  12. <%
  13.  
  14.     Do While CurrentColumn<=5
  15.  
  16.     Dim thumbnail 
  17.     thumbnail = rsCard("ThumbnailURL")
  18.  
  19.     Dim totalThumbnails 
  20.     totalThumbnails = 1
  21.     If Not IsBlank(rsCard("NewImageOne")) Then
  22.         totalThumbnails = 2
  23.         If Not IsBlank(rsCard("NewImageTwo")) Then
  24.             totalThumbnails = 3
  25.             If Not IsBlank(rsCard("NewImageThree")) Then
  26.                 totalThumbnails = 4
  27.                 If Not IsBlank(rsCard("NewImageFour")) Then
  28.                     totalThumbnails = 5
  29.                     If Not IsBlank(rsCard("NewImageFive")) Then
  30.                         totalThumbnails = 6
  31.                         If Not IsBlank(rsCard("NewImageSix")) Then
  32.                             totalThumbnails = 7
  33.                             If Not IsBlank(rsCard("NewImageSeven")) Then
  34.                                 totalThumbnails = 8 
  35.                                 If Not IsBlank(rsCard("NewImageEight")) Then
  36.                                     totalThumbnails = 9 
  37.                                 End If                                
  38.                             End If                            
  39.                         End If                        
  40.                     End If                    
  41.                 End If                
  42.             End If            
  43.         End If        
  44.     End If
  45.  
  46.      ' randomize()
  47.      ' Dim pictureNumber
  48.      ' pictureNumber = CInt((rnd() * totalThumbnails) + 1)
  49.  
  50.  
  51.     ' Change picture every second
  52.      Dim pictureNumber
  53.      pictureNumber = (second(Time) MOD totalThumbnails) +1
  54.  
  55.     If pictureNumber>totalThumbnails Then
  56.         pictureNumber = 1
  57.     End If
  58.  
  59.     If pictureNumber = 2 then
  60.         thumbnail = rsCard("NewImageOne")
  61.     End If
  62.  
  63.     If pictureNumber = 3 then
  64.         thumbnail = rsCard("NewImageTwo")
  65.     End If
  66.  
  67.     If pictureNumber = 4 then
  68.         thumbnail = rsCard("NewImageThree")
  69.     End If
  70.  
  71.     If pictureNumber = 5 then
  72.         thumbnail = rsCard("NewImageFour")
  73.     End If
  74.  
  75.     If pictureNumber = 6 then
  76.         thumbnail = rsCard("NewImageFive")
  77.     End If
  78.  
  79.     If pictureNumber = 7 then
  80.         thumbnail = rsCard("NewImageSix")
  81.     End If
  82.  
  83.     If pictureNumber = 8 then
  84.         thumbnail = rsCard("NewImageSeven")
  85.     End If
  86.  
  87.     If pictureNumber = 9 then
  88.         thumbnail = rsCard("NewImageEight")
  89.     End If
  90.  
  91.     If IsNull(thumbnail)  then
  92.         thumbnail = rsCard("ThumbnailURL")
  93.     End If
  94.  
  95. %>


Thanks
Richard
Nov 13 '07 #1
Share this Question
Share on Google+
1 Reply


jhardman
Expert 2.5K+
P: 3,405
Richard,

Both are possible, perhaps each time you make a selection you could add it to a session variable like this:
Expand|Select|Wrap|Line Numbers
  1. if session("picsViewed") <> "" then session("picsViewed") = session("picsViewed") & ","
  2. session("picsViewed") = session("picsViewed") & pictureNumber
then every time you select your random number, just check to make sure it isn't already on the list. Or you could just save the number of the last one viewed and pull up the next one the next time you visit. Notice that the session variables are held in memory for every page a single user visits during a given session. If you want the memory to last longer, you will need to send the info to a cookie. Let me know if this helps.

Jared
Nov 17 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.