Make Revenue With Your Own Banner Management System - Displaying and tracking banners, impressions and click-thrus
(Page 8 of 11 )
By now you should have created the four pages that I described in part one: addbanner1.asp, addbanner2.asp, banners.asp and delbanner.asp. You should save these pages in some sort of admin folder and use your Web server to configure the security permissions on this directory so that a username a password is required to access your banner scripts.
Having said that, I'll now demonstrate the code we'll use to retrieve a banner from our database, display it on our Web page and track both impressions and click-thrus for each banner.
Displaying a banner on your site:No doubt you've been to thousands of Websites that display banners across the top of the screen. These could be 468x60 banners, 460x60, 215x125 etc. The point is that banners are the most popular form of advertising on the Internet.
To display a banner from the database on our site, four steps are required as pictured here:

Create the following code and save it to a file called bannercode.asp
<%@ Language="VBScript" %>
<!-- METADATA Type="TypeLib" File="c:\program files\common files\system\ado\msado15.dll" -->
<%
function GetBanner()
dim objConn
dim objComm
dim objRS
dim strBanner_VirtualPath
dim strBannerHTML
dim intNumBanners
dim intRandom
set objConn = Server.CreateObject("ADODB.Connection")
set objRS = Server.CreateObject("ADODB.Recordset")
strBanner_VirtualPath = "/banners/"
objConn.Open "Provider=SQLOLEDB; Data Source=localhost;Initial Catalog=myAdStuff; UId=sa; Pwd="
objRS.ActiveConnection = objConn
objRS.LockType = adLockReadOnly
objRS.CursorType = adUseForwardOnly
objRS.Open "select count(*) from banners"
intNumBanners = objRS.Fields(0).Value
if intNumBanners = 0 then
exit function
end if
Randomize
intRandom = int(rnd(1)*intNumBanners)
objRS.Close
objRS.Open "select * from banners"
objRS.Move intRandom
strBannerHTML = "<a href='bannerclick.asp?bannerId=" & objRS("bannerId") & "'><img border='0' src='" & strBanner_VirtualPath & objRS("bannerImage") & "'<>/a>"
Response.Write strBannerHTML
objConn.Execute "UPDATE banners SET bannerImpressions =bannerImpressions + 1 WHERE bannerId = " & objRS("bannerId")
objConn.Close
set objConn = nothing
set objRS = nothing
end function
%>Now, let's break down the unfamiliar code...
Next: The code in detail >>
More ASP Articles
More By Mitchell Harper