欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

广告播放和跟踪系统的制作

程序员文章站 2022-09-14 10:14:26
首先你需要一个放置你的广告,我们共用了2个表: blbanners 和 tblvendors表:tblbanners结构表如下:bid - auto number (广告id)bb...
首先你需要一个放置你的广告,我们共用了2个表: blbanners 和 tblvendors表:
tblbanners结构表如下:
bid - auto number (广告id)
bbanner - text (图像文件)
busedviews - number (# 标准的广告显示次数)
btotalviews - number (# of impressions the vendor has paid for)
bclicks - number (# 标准的广告点击次数)
burl - text (网站url)
bshow - yes/no (用来标识广告是显示还是隐藏)
vid - number (卖主 id)

tblvendors表结构如下:
vid - autonumber (卖主 id - 链到tblbanners.vid)
vname - text (卖主的名字)
etc..........

第一步

现在,这个数据库已经建立了,你需要有随机地在我们的网页中显示广告并且计算显示次数。:
dsn链接不讲了,如果不会,你可以到以下地址看看:
https://www.ask.com/toolbox.asp?expand=true&id=2#tool

如果是sql,可以采用下面的相似语句:

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]));"

在上面的sql语句中,只有当bshow标志是true而且usedviews(显示客户广告次数)小于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 banners 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 banners 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) %>