473,698 Members | 2,616 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

select next database field rather than random

229 New Member
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
1 1462
jhardman
3,406 Recognized Expert Specialist
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

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

Similar topics

3
2014
by: Bob Bedford | last post by:
I've a site where companies add their article. I'de like to provide a "lasts articles" table. By this, I'll show last articles inserted. But I won't always the same articles at any refresh. Question 1: how to get a "random" selection from the database, giving more priority to the last inserted (the ones with higher articleID) Question 2: I'd like to provide one article by client. I won't show 3 articles from the same client only because...
3
5190
by: Mohammed Mazid | last post by:
Hi folks! Can anyone please help me with this? I am developing a Quiz program but I am stuck with "multiple answers". Basically I need some sort of code that would select multiple answers using check boxes. For example, a question such as
2
9620
by: Jas | last post by:
I want an ASP page with a dropdown and a simple button. Every time the user chooses an item from the dropdown and clicks on the button i want that value written below in list and allow user to select more. Also how can these choices be saved somehow so tha when the user goes to the next page the choices he made can be written to the database. For example The choices in the dropdown may be
8
17047
by: Adam Nemitoff | last post by:
Is is possible to construct a SELECT statement that contains a WHERE clause that uses the value from a column in the "next" row? ie. given a table with a single field named "myField" with the following values I want a SELECT statement that selects the rows "WHERE myField='1' and myField = '2' ": 5 6 1
8
5143
by: K.Fawcett | last post by:
I am doing a simple insert into a table and I would like the data to be retrieved in the order it is inserted not by what appears to be alphabetical order. insert into mytbl values('c') insert into mytbl values('b') insert into mytbl values('a') select * from mytbl yields
11
4425
by: pmarisole | last post by:
I am trying to use the vbscript "split" function on a multi-select field. I am trying to do a mass update of several records at a time. I am getting an error and I'm not sure what to do. Here is the code if someone could help... strID = split(request.form("proj"), ", ") projstat = split(request.form("rojstat"),",") impr = split(request.form("impr"),",") idate =...
5
2598
by: john | last post by:
In this single-user app I have a form with members. In the related table I have a field 'Select' with which the user can select a record. I have two buttons on the form (All and None) that select either all records or none. Those buttons both work with an edit query. It works except for the current record since that is locked. To avoid that I have added code that specifically changes the Select value of the current record by Select=-1 (or...
22
12476
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source=" & msDbFilename moConn.Properties("Persist Security Info") = False moConn.ConnectionString = msConnString moConn.CursorLocation = adUseClient moConn.Mode = adModeReadWrite' or using default...same result
1
4024
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which are not bound, I select from the bottom set and add to the top set which works fine, but now i decide to remove an item from the top set. when i tried to use a remove item code it worked fine, it did delete the item form the list but it added...
0
8610
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7740
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.