|
| |
Display Random Banner Works, but i don't know how to link it
View related threads:
(in this forum
| in all forums)
|
Logged in as: Guest
|
|
|
jonance
Posts: 302 From: Louisville KY USA Status: offline
|
Display Random Banner Works, but i don't know how to li... - 9/15/2009 18:00:16
Hi, I have a code that i edited a bit to display a random banner. THis works fine and on refresh a different banner from my table is displayed. However in each row there is the 'name' field, which is the banner url....but also a 'linkurl' field. I need to be able to have each rotating banner linked to the proper url. This is where i am totally lost. I am trying to learn asp so if someone can tell me how i need to edit the code, i would greatly appreciate it and it would help me to learn as well. Code is below...thanks, John
<%
'declare your variables
dim connection, recordset, sConnString, sql
dim intRandomNumber, intTotalRecords, i
'declare SQL statement that will query your database
sql = "SELECT name FROM listings"
'create ADO connection and recordset object
Set connection = Server.CreateObject("ADODB.Connection")
Set recordset = Server.CreateObject("ADODB.Recordset")
'define the connection string, specify database
'driver and the location of database
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("/fpdb/louisvilleguide.mdb")
'Open the connection to the database
connection.Open(sConnString)
'Open the recordset object executing the SQL
recordset.Open sql, connection, 3, 1
'count the number of records and hold this is the variable intTotalRecords
intTotalRecords = recordset.RecordCount
Randomize()
intRandomNumber = Int(intTotalRecords * Rnd)
'move to the random number returned
recordset.Move intRandomNumber
'loop through the total number of fields
For i = 0 to recordset.Fields.Count - 1
'write out the field value
Response.write("<img border='0' src='banners/" & recordset(i) & "'>")
Next
'close the table
response.write("")
'close the recordset and connection objects and free up resources
recordset.Close
Set recordset=Nothing
connection.close
Set connection=Nothing
%>
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|