Buddy Ring Script for web ring surf ring use

I cobbled together this script for use in a ring surfing script. I couldn't find preexisting code that was free so I had to figure out how to write it myself. It was necessary to have code that would match the current record to the site id that was given to it in a string, and then also return the previous and next records. When a user has navigated to the beginning of the ring, then the "Previous" site link becomes the last site in the ring. When a user has navigated to the end of the ring, then the "Next" site link becomes the first site in the ring.

My first attempt was far more complicated than this final code. I realized I was trying to make it much more difficult than it actually was.

In essence, what you do is:
1. Return the current site identification key to the script, done here with a querystring CInt((request.querystring("site"))).
2. Tell the record set to go to the first record. Name that record key as a variable.
3. Tell the record set to go to the last record. Name that record key as a variable.
4. Tell the record set to keep going backwards until it comes to a record id key that is less than the current site identification key. Name that record key as a variable.
5. Tell the record set to keep going forward until it comes to a record id key that is greater than the current site identification key. Name that record key as a variable.
6. Tell the record set that if the first record key isn't less than the current record key, that the next "previous" record to go to is the last one.
7. Tell the record set that if the last record key isn't greater than the current record key, that the next "next" record to go to is the first one.
8. Then do a response write or response redirection of each of the named variables!

I haven't posted administration and signup pages and I haven't posted the database, because this file here was the one that was difficult to work out, as far as I was concerned. If anyone can't generate their own administration pages, they can buy them from me. ;)

This code may also be useful if you simply need to know how to cycle through a recordset forward and back and to get the current, previous and next records as a group of three.

 

<%@ Language="VBScript" %>
<% Option Explicit
'you may want to comment out the redirects to test script %>

<%
Response.expires = 0
Response.expiresabsolute = Now() - 1
Response.addHeader "pragma", "no-cache"
Response.addHeader "cache-control", "private"
Response.CacheControl = "no-cache"
Response.Buffer = True
%>

<%
dim CursorType,adOpenStatic



dim connection, recordset, sConnString, sql
dim intRandomNumber, intTotalRecords, i

sql = "SELECT * FROM SITES"


Set connection = Server.CreateObject("ADODB.Connection")
Set recordset = Server.CreateObject("ADODB.Recordset")
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("buddyring.mdb")

'Open the connection to the database
connection.Open(sConnString)


recordset.Open sql, connection, 3, 3
intTotalRecords = recordset.RecordCount


recordset.movelast
dim strLast, strLurl
strLast = (recordset.Fields("siteID"))
strLurl = (recordset.Fields("URL"))

recordset.movefirst
dim strFirst,str1sturl
strFirst = (recordset.Fields("siteID"))
str1sturl = (recordset.Fields("URL"))
dim strNum
strNum = CInt((request.querystring("site")))



do until recordset.Fields("siteID")=strNum
recordset.MoveNext
loop
dim strRec, strURL
strRec = (recordset.Fields("siteID"))
strURL = (recordset.Fields("URL"))
response.write"First Record: " & strFirst &"<BR>"
response.write"Current Record: "& strRec & "<BR>"
response.write"Last Record: " & strLast &"<BR>"

dim strNPrev
dim strFURL
if strFirst < strNum then
do until recordset.Fields("siteID")<strNum
recordset.MovePrevious
loop
strNPrev = recordset.Fields("siteID")
strFURL = recordset.Fields("URL")
else
strNPrev = strLast
strFURL = strLurl
end if

response.write "Previous Record: " & strFURL & "?siteid="& strNPrev &"<BR>"


dim strNext
dim strNURL
if strNum < strLast then
do until recordset.Fields("siteID")>strNum
recordset.MoveNext
loop
strNext = recordset.Fields("siteID")
strNURL = recordset.Fields("URL")
else
strNext = strFirst
strNURL = str1sturl
end if
response.write "Next Record: " & strNURL &"?siteid=" & strNext &"<BR>"
if request.querystring("pg")="prev" then
response.redirect strFURL & "?siteid="& strNPrev
elseif request.querystring("pg")="next" then
response.redirect strNURL &"?siteid=" & strNext
elseif request.querystring("pg")="random" then


Dim rndMax
rndMax = CInt(recordset.RecordCount)

recordset.MoveFirst

Dim rndNumber
Randomize Timer
rndNumber = Int(RND * rndMax)

recordset.Move rndNumber

Response.Redirect(recordset("URL"))
end if

recordset.Close
Set recordset=Nothing
connection.close
Set connection=Nothing
%>

ASP Examples Menu of Active Server Pages scripts code Classic ASP

Classic ASP Active Server Pages Examples, code, tutorials, scriptsASP Examples Menu (below*)



Active Server Pages | ASP | Scripts | Tutorials | Code | Web Programming | Examples
Active Server Pages ASP code examples, tutorials, and snippets for use in Programming interactive websites.

NOTE: Recently changed hosting and url so some demos aren't working now because I haven't updated pathing; if you find omissions or errors let me know.
 

*

Multiple records per row with paging

Display multiple records per row

Get ID of newly inserted record, Classic ASP, Access Database

Javascript timer with ASP to keep track of time expired until login expires / timeout session is up

Multiple Javascript event functions triggered from single form onsubmit

Get Querystring key names along with querystring variables

ASP Youtube Downloader  Version FOUR
All ASP code. Allows user client side downloads of Youtube videos. You have the option to allow files to be saved directly to your site also.

ASP/PHP video downloader (Works better than ASP for large files)

Use ASP to dynamically parse a Youtube XML playlist to render to html.

Zip up an archive file of your site for backup if you need to restore website with ASP and free Zip Component.

Zip all files in a folder into an archive or backup file dynamically by specific file extension.

Sanitize or clean price cost field for database insertion or display.

Javascript image dimensions and image file size preview.

Put recordset into array, assign keys to the records then use record associated with specific array key as a variable elsewhere.

Access Database Interface Generator Wizard to read your table and field names and to create a table display.

Combining dropdown selection box menu with dynamic ASP database page.

How to redirect user to original page they tried to view before logging, after they are logged in.

Previous/Current/Next Records, or Buddy Ring Script

Custom ASP 404 page not found error script sends visitors to virtual folders

ASP Example: Combine ASP with Javascript for popup windows
dynamically sized to image dimensions.

ASP Example: How to use ASPJPEG to create thumbnails
Click for free Highly recommended thumbnailer for which you don't need Server access

ASPjpeg: How to re-scale aspect ratio of thumbnails by height instead of width.

ASP Example: What if your host has an older version of ASPJPEG that doesn't support gifs?

Using inline frames as "dynamic includes" (offline for updating)

Select Count Distinct Records for Access Database

Upload Image to folder and insert filename into database

Get date in such a way that it can be made part of a file name

Isolate a file name away from its path or extension or strip a path from a file name or strip characters from database field

User-customized on-the-fly stylesheet css files

Enhanced Page Hits Counter (also counts downloads and menu link hits)

Loop through array and compare to string with select case

Aphabetical Paging for your ASP scripts

Web Wiz Guide's Site Searcher Script modified as a file content indexer

Let Users Select How Many Records to View

Access Database for your PayPal IPN scripts

Miscellaneous collected code

You don't have to be a genius, just persistent, to write original Active Server Pages scripts

Software Recommendation: bare_bones_no_bells_and_whistles_asp_code_generator_database_interface_maker

--Lil at gmail.com