Bilgisayar Bölümü ASP Kod ve Script Arşivi


Banner-ad rotation and tracking system

First you need a database To store your banners. We are using 2 tables;
tblBanners And tblVendors:

tblBanners:
bID - auto number (banner
ID)
bBanner - Text (image file)
bUsedViews - number (# of views the banner
has received)
bTotalViews - number (# of impressions the vendor has paid
For)
bClicks - number (# of clicks the banner has received)
bURL - Text
(URL of the site)
bShow - yes/no (used To show And hide banners)
vID -
number (vendor ID)

tblVendors:
vID - autonumber (vendor ID - links To
tblBanners.vID)
vName - Text (Vendor's name)
etc..........


Now
that the database Is Set up, we need To randomly display the banner On our pages
And increment the 'views' by 1:

First you need To Open your database
connection On the page you want your banner To be viewed On. We use a DSN-less
connection; you can find it at the following
address:

http://www.askasp.com/toolbox.asp?Expand=True&ID=2#tool

Here
Is what the SQL might look Like:

SQL = "Select tblBanners.bID,
tblBanners.bImage, tblBanners.bUsedViews, tblBanners.bLastViewed "

SQL = SQL
& "FROM tblBanners "
SQL = SQL & "WHERE (((tblBanners.bShow)=True)
And ((tblBanners.bTotalViews)>[tblBanners].[bUsedViews]));"


In the
above SQL, we are checking For the 'bShow' flag To be True, And that the
UsedViews Is less than the TotalViews.

Now that we have all of the
banners that we can display, we need To display a random one. We can Do this by
grabbing the total number of banners, moving To the first record, And the moving
To a random number, For example:


Dim rndMax,
rndNumber

Randomize

rndMax =
Int(RecordSet.RecordCount)
rndNumber = Int(RND * rndMax)


RecordSet.Move rndNumber


Now that we have moved To our random
banner, we now need To display the banner On our page (I am sure you know how To
Do that, so I wont bore you With the details). However, Instead of using the
banner's URL In the link, we are going To use a redirect page so we can count
the clicks. All we need To Do Is use the banner ID In the HREF tag, For
example:

a href="redirect.asp?ID=<%= BANNER ID %>"

Now that
we have the link Set up, we can move On To our redirect.asp page. On this page,
we are going To grab the ID that we are passing In the Query String, And
grabbing the RecordSet that matches. Once we have the RecordSet, we can grab the
banner's URL, increase the Clicks by 1, And send the user To the destination
URL. Below Is the code For the redirect.asp page:

<%
If
Request.QueryString("ID") = "" Then
Response.Redirect("default.asp")
End
If

Dim varSiteToRedirect, varURLToRedirect

varSiteToRedirect =
Int(Request.QueryString("ID"))


SQL = "Select tblBanners.bID,
tblBanners.bURL, tblBanners.bClicks "

SQL = SQL & "FROM tblBanners
"

SQL = SQL & "WHERE (((tblBanners.bID)=" & varSiteToRedirect &
"));"

varDatabaseName =
"ask_asp_data.mdb"
%>

<!--#include
file="common/data_conn_open.asp"-->

<%
If Not RecordSet.BOF
Then
RecordSet.MoveFirst
End If

varURLToRedirect =
RecordSet.Fields("bURL")

RecordSet.Fields("bClicks") =
(RecordSet.Fields("bClicks") +
1)
RecordSet.Update
%>

<!--#include
file="common/data_conn_close.asp"-->

<%
Response.Redirect(varURLToRedirect) %>

ASP Kitabı

 

Faydalılar: Altın Fiyatları |Hediye Kolye | pırlanta fiyatları
Ana Sayfa  Sık Kullanılanlara Ekle   admin[at]bilgisayarbolumu.com | © 2006 - 2022 Bilgisayarbolumu.com