您的位置:首页网页设计ASP实例 → 建立一个广告交换及跟踪系统

建立一个广告交换及跟踪系统

时间:2004/11/7 2:57:00来源:本站整理作者:蓝点我要评论(0)

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"

%>







<%

If Not RecordSet.BOF Then

RecordSet.MoveFirst

End If



varURLToRedirect = RecordSet.Fields("bURL")



RecordSet.Fields("bClicks") = (RecordSet.Fields("bClicks") + 1)

RecordSet.Update

%>







<% Response.Redirect(varURLToRedirect) %>




相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 迅雷新手完全入门手册 asp下面javascript上传图片限制格式大小方法告诉大家网页弹出窗口应用总结ASP常见错误类型大全asp常见错误分析和解决办法

人气排行 总是弹出visual studio 实时调试器 三种解决SQLSERVER存储过程及调用详解Asp获取真实IP地址ASP中连接Mssql的几种方法一个简单好用的UBB编辑器(含代码)如何用Split将字符串转换为数组并获取数组下ASP防止表单重复提交的办法告诉你免费的简单聊天室源代码