select next database field rather than random

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fran7
    New Member
    • Jul 2006
    • 229

    select next database field rather than random

    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!


    Code:
    	<%  
    	If Not rsCard.EOF Then
    	rsCard.AbsolutePage = intPage 
     
    
       For intRecord = 1 To rsCard.PageSize
    	CurrentColumn=1
    %>
    <tr>     
    
    
    <%
    	
    	Do While CurrentColumn<=5
    	
    	Dim thumbnail 
    	thumbnail = rsCard("ThumbnailURL")
    	
    	Dim totalThumbnails 
    	totalThumbnails = 1
    	If Not IsBlank(rsCard("NewImageOne")) Then
    		totalThumbnails = 2
    		If Not IsBlank(rsCard("NewImageTwo")) Then
    			totalThumbnails = 3
    			If Not IsBlank(rsCard("NewImageThree")) Then
    				totalThumbnails = 4
    				If Not IsBlank(rsCard("NewImageFour")) Then
    					totalThumbnails = 5
    					If Not IsBlank(rsCard("NewImageFive")) Then
    						totalThumbnails = 6
    						If Not IsBlank(rsCard("NewImageSix")) Then
    							totalThumbnails = 7
    							If Not IsBlank(rsCard("NewImageSeven")) Then
    								totalThumbnails = 8 
    								If Not IsBlank(rsCard("NewImageEight")) Then
    									totalThumbnails = 9 
    								End If								
    							End If							
    						End If						
    					End If					
    				End If				
    			End If			
    		End If		
    	End If
    
    	 ' randomize()
    	 ' Dim pictureNumber
    	 ' pictureNumber = CInt((rnd() * totalThumbnails) + 1)
    	
    	
    	' Change picture every second
    	 Dim pictureNumber
    	 pictureNumber = (second(Time) MOD totalThumbnails) +1
    	 
    	If pictureNumber>totalThumbnails Then
    		pictureNumber = 1
    	End If
    	
    	If pictureNumber = 2 then
    		thumbnail = rsCard("NewImageOne")
    	End If
    	
    	If pictureNumber = 3 then
    		thumbnail = rsCard("NewImageTwo")
    	End If
    	
    	If pictureNumber = 4 then
    		thumbnail = rsCard("NewImageThree")
    	End If
    	
    	If pictureNumber = 5 then
    		thumbnail = rsCard("NewImageFour")
    	End If
    	
    	If pictureNumber = 6 then
    		thumbnail = rsCard("NewImageFive")
    	End If
    	
    	If pictureNumber = 7 then
    		thumbnail = rsCard("NewImageSix")
    	End If
    	
    	If pictureNumber = 8 then
    		thumbnail = rsCard("NewImageSeven")
    	End If
    	
    	If pictureNumber = 9 then
    		thumbnail = rsCard("NewImageEight")
    	End If
    	
    	If IsNull(thumbnail)  then
    		thumbnail = rsCard("ThumbnailURL")
    	End If
       
    %>


    Thanks
    Richard
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    Richard,

    Both are possible, perhaps each time you make a selection you could add it to a session variable like this:
    [code=asp]if session("picsVi ewed") <> "" then session("picsVi ewed") = session("picsVi ewed") & ","
    session("picsVi ewed") = session("picsVi ewed") & pictureNumber[/code] 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

    Comment

    Working...