View Full Version : Get all records, loop through them, repeat infinitely

04-11-2007, 08:09 PM

OK, forgive me if I'm not using the correct language, but I have an ad-display system where I need to get all the current records in the recordset and loop through them in some sort of an array. When the last record is reached, I need to go back to the first record.

For example, say there are 3 records:
f_ID 2
f_Name BMW Z4
f_Priority 44

f_ID 5
f_Name BMW Motorcycle
f_Priority 17

f_ID 12
f_Name BMW 5-Series
f_Priority 99

Here is my current code, (http://portal.labellasera.com/screensaver.htm) which I have somewhat commented (in green). My current problem is, if there are records missing in between, (1, 2, 3, 5, 6, 7), then it will still get that image, even though it doesn't exist. So somehow, hopefully with your extreme help (I haven't even gotten a slight clue), I can get this thing working.

Overall, what I need to acheive is to get the first good record, then redirect to the next for 'x' seconds, then redirect to the next for 'x' seconds, then redirect to the last record for 'x' seconds, then go back to the first record. Any help you can give is greatly appreciated.

Thanks in advance,

04-11-2007, 09:59 PM
What it sounds like you want a spinner function, doing a specific thing until a certain point and then restart.

Numeric and Date spinners are usually found with up/down arrows and dates/times/numbers, but can be used for anything (Look at the JS forum and look for my post (and GlennGV's) post on number spinners).

As to what you need to do to fix this -- I don't know yet. Your code, written with Dreamweaver, is a little confusing. You are constantly jumping in and out of ASP, and using <%= and response.write together in the same statement (<%= is the same as response.write).

The easiest way to do this would be to use the FirstRecord variable as a starting point.

Dim PreviousPage
Dim NextPage
Dim FirstRecord
PreviousPage = request.QueryString("ID")
NextPage = PreviousPage +1
FirstRecord = (rs_screensaverall.Fields.Item("f_ID").Value)

When you get to the LastRecord (rs.EOF), then push FirstRecord variable.

If request.QueryString <> "" then
If Not rs_screensaver.EOF Or Not rs_screensaver.BOF Then
response.write("<div class=""wraptocenter""><img alt=""" & rs_screensaver.Fields.Item("f_Name").Value & """ src=""_ads/" & rs_screensaver.Fields.Item("f_File").Value & """ /></div>")
response.redirect("screensaver.asp?ID=" & FirstRecord)
End If
End If

You will see that I accomplished this with 1 set of delimiters, rather than your 4 or 5 (I know, it's Dreamweaver...).

If the code hits the EOF or BOF, then it does the same as hitting the Default Page link.

NOTE: I usually have the ability to test all my work before sending it out here, but I can't in this case. Please let me know if you have any issues with the code and we can work them out.