Forums
This topic is locked
Random Record Behavior
Posted 21 Sep 2010 19:38:32
1
has voted
21 Sep 2010 19:38:32 Natalie Patterson posted:
I'm using the random record behavior in several locations on one page. Can you tell me what line of code to tweak in the behavior to not use a record more than once per page? For example I have 3 image ads displaying on the left side of my page each with the random record behavior applied. Sometime 2 of the same image will appear in that left column. I want the script to skip a record/image if it's already in use. Here's the behavior/script code:
<
%' Moving to random record - Steven Jones' Extension
If Not(rsLeaderboard.bof and rsLeaderboard.eof) Then
' reset the cursor to the beginning
If (rsLeaderboard.CursorType > 0) Then
rsLeaderboard.MoveFirst
Else
rsLeaderboard.Requery
End If
rsLeaderboard_totalrn = -1
rsLeaderboard_totalrn = rsLeaderboard.RecordCount ' ony works on some recordsets, but much faster
If (rsLeaderboard_totalrn = -1) Then ' and if it didn't work, we still have to count the records.
' count the total records by iterating through the recordset
rsLeaderboard_totalrn=0
While (Not rsLeaderboard.EOF)
rsLeaderboard_totalrn = rsLeaderboard_totalrn + 1
rsLeaderboard.MoveNext
Wend
' reset the cursor to the beginning
If (rsLeaderboard.CursorType > 0) Then
rsLeaderboard.MoveFirst
Else
rsLeaderboard.Requery
End If
End If
' now do final adjustments, and move to the random record
rsLeaderboard_totalrn = rsLeaderboard_totalrn - 1
If rsLeaderboard_totalrn > 0 Then
Randomize
rsLeaderboard.Move Int((rsLeaderboard_totalrn + 1) * Rnd)
End If
End If
' all done; you should always check for an empty recordset before displaying data
%>