Click to See Complete Forum and Search --> : Rotating Banner Ads
Hi.
I've been looking for awhile for a code for rotating banner ads. I don't want the banner to change while the person is still on the same page, but rather have it change when I person goes to another page. I'm not talking about the same banner every time a person goes to a same page (Like every time a person goes to the home page, they won't see an ad for yahoo, atleast not all the time).
I can't find a code like this which isn't 500 lines long. If anyone can help out, that would be great! Thanks! :)
russell_g_1
09-03-2005, 10:44 AM
do you just want some kind of random banner choosing code that can be stuck in every page?
russell_g_1
09-03-2005, 11:15 AM
here's a simple example of selecting a random banner from a table and displaying it. assuming you can put all the possible banners in a database table.
the table looks like banners(id,name,imageurl,linkurl)
this just displays an image with an anchor around it. if you want to do it with iframes instead it should be even easier to be honest.
you might need different sql as well, the query below was written for ms sql server.
<html>
<head>
<style>
div#page
{
width:500px;
border:1px solid black;
}
div#banner
{
width:500px;
height:80px;
float:left;
background-color:#00ff00;
border:1px solid black;
}
div#banner img
{
border:0px;
}
div#main
{
float:left;
clear:left;
padding:10px;
width:100%;
}
</style>
</head>
<body>
<div id="page">
<%
writeBanner()
%>
<div id="main">rest of page</div>
</div>
</body>
</html>
<%
function writeBanner()
dim sql
response.write "<div id=""banner"">"
sql = "select imageurl,linkurl from banners where id = (select floor(rand() * (select count(*) from banners)) + 1)"
if runsql(sql,rs) then
if not rs.eof then
response.write "<a href=""" & rs("linkurl") & """>"
response.write "<img src=""" & rs("imageurl") & """>"
response.write "</a>"
end if
end if
response.write "</div>"
end function
function runSQL(SQL,rs)
on error resume next
set myRs = createobject("ADODB.recordset")
myRs.Open SQL,"DATABASE=filesys1;UID=sa;PWD=qwertyuiop;DSN=filesys1", 1, 3
set rs = myRs
if err then
runSQL = false
else
runSQL = true
end if
end function
%>