Error » Certification & Programming center Error !! » Programming tutorials » Rotating Banner Ads using a Database(asp)

Programming tutorials All Knowledge Info and links to posted here

Post New Thread Reply
  Rotating Banner Ads using a Database(asp)
LinkBack Thread Tools Display Modes
Old 14-Dec-2006, 01:39 AM   #1 (permalink)
Administrator
 
Anilrgowda's Avatar

Posts: 18,715
Join Date: Jan 2006
Rep Power: 10 Anilrgowda is on a distinguished road

IM:
Default Rotating Banner Ads using a Database(asp)

This is simple Ad rotation system based on ASP-SQL Server combination.
All Ad info (except images, which are asumed to be in current directory) is stored in SQL server table caled <CODE>Banners</CODE>.
The system is intended to provide easy random rotation and counting of Ad showing and clicks.

Data structure
First we will set up a table in the database called <CODE>Banners</CODE> and it will have the following structure:
<CENTER><TABLE cellSpacing=1 border=1><TBODY><TR><TH colSpan=2><CODE>Banners</CODE></TH></TR><TR><TD>BannerID</TD><TD>Long</TD></TR><TR><TD>Image</TD><TD>varchar(100)</TD></TR><TR><TD>URL</TD><TD>varchar(100)</TD></TR><TR><TD>Hint</TD><TD>varchar(100)</TD></TR><TR><TD>Shown</TD><TD>Long</TD></TR><TR><TD>Clicked</TD><TD>Long</TD></TR></TBODY></TABLE></CENTER>
Here is some example data:
<CENTER><TABLE cellSpacing=1 border=1><TBODY><TR><TH>BannerID</TH><TH>Image</TH><TH>URL</TH><TH>Hint</TH><TH>Shown</TH><TH>Clicked</TH></TR><TR><TD>1</TD><TD>gausBanner.gif</TD><TD>http://www.gaus.co.yu</TD><TD>Visit our site</TD><TD>1</TD><TD>1</TD></TR></TBODY></TABLE></CENTER>
and here is how can you add table to your SQL database:
<TABLE width="95%" border=0><TBODY><TR><TD width="100%" bgColor=#cccccc><CODE><XMP>create table Banners(BannerID int identity PRIMARY KEY,Image varchar(100),URL varchar(100),Hint varchar(100),Shown int,Clicked int,)</XMP></CODE></TD></TR></TBODY></TABLE>
Retrieving and diplaying Ad's
Everything you need is just put folowing line of code anywhere you want Ad to be shown:
<TABLE width="95%" border=0><TBODY><TR><TD width="100%" bgColor=#cccccc><CODE><!--#include virtual="BannersInc.asp"--></CODE> </TD></TR></TBODY></TABLE>
and to copy following two files in the same directory.
<CODE>BannersInc.asp</CODE> shows random Ad from your Banners table and creates link to destination URL.
Here is code for <CODE>BannersInc.asp</CODE> file.
BannersInc.asp
<TABLE width="95%" border=0><TBODY><TR><TD width="100%" bgColor=#cccccc><CODE><%@ Language=VBScript %>
<%<XMP> Response.Buffer=True 'Define our ADO constants const adOpenStatic = 3 const adLockOptimistic = 3 '----- Create and Open Connection Set MyConnection = Server.CreateObject("ADODB.Connection") MyConnection.ConnectionString = "PROVIDER=SQLOLEDB;SERVER=YourServerName;UID=YourU ID;" & _ "PWD=YourPWD;DATABASE=YourDATABASE" MyConnection.Open '----- Pick Ad from database SQLBanners = "Select * from Banners" Set Banners = Server.CreateObject("ADODB.Recordset") Banners.CursorType = adOpenStatic Banners.LockType = adLockOptimistic Banners.Open SQLBanners, MyConnection Randomize Timer Banners.Move Int(RND * CInt(Banners.RecordCount)) '----- Increment Shown field value Banners("Shown") = Banners("Shown") + 1 Banners.Update '----- Create and display Response ImageString = "" ResponseString = "" & ImageString & "" Response.Write ResponseString Response.End '----- Clean up memory Banners.Close MyConnection.Close Set Banners=Nothing Set MyConnection=Nothing</XMP>%></CODE></TD></TR></TBODY></TABLE>
Be sure to provide correct values for SERVER,UID,PWD and DATABASE If your Images are not in current directory then you should adjust <CODE>ImageString</CODE>. Each time Ad is clicked users Clicked value for appropriate Ad is incremented and users browser is redirected to Ad's URL.
Here is code for <CODE>RedirectMe.asp</CODE>
RedirectMe.asp
<TABLE width="95%" border=0><TBODY><TR><TD width="100%" bgColor=#cccccc><CODE><%@ Language=VBScript %>
<% <XMP> Response.Buffer=True 'Define our ADO constants const adOpenStatic = 3 const adLockOptimistic = 3 '----- Create and Open Connection Set MyConnection = Server.CreateObject("ADODB.Connection") MyConnection.ConnectionString = "PROVIDER=SQLOLEDB;SERVER=YourServerName;UID=YourU ID;" & _ "PWD=YourPWD;DATABASE=YourDATABASE" MyConnection.Open '----- Increment Clicked field value SQLBanners = "Select * from Banners Where BannerID=" & Request.QueryString("BannerID") Set Banners = Server.CreateObject("ADODB.Recordset") Banners.CursorType = adOpenStatic Banners.LockType = adLockOptimistic Banners.Open SQLBanners, MyConnection Banners("Clicked") = Banners("Clicked") + 1 Banners.Update Response.Redirect(Request.QueryString("URL")) Response.End '----- Clean up memory Banners.Close MyConnection.Close Set Banners=Nothing Set MyConnection=Nothing</XMP>%></CODE></TD></TR></TBODY></TABLE>
After some short and easy customization and running this code on your site, you will have some useful, additional information about your Ad's which can be later easily extracted from <CODE>Banners</CODE> table. Happy Programming!
Anilrgowda is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
   


   
Post New Thread Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CellNet 360 Rotating Banner Tool 1.1 SlimShady Application Downloads 0 05-Apr-2008 11:34 AM
Websmartz Banner Designer 3.0 iTouch Application Downloads 0 26-Feb-2008 01:46 AM
Trendy Forum Banner Iphone Graphic tutorials 0 16-Apr-2007 11:24 PM
Animated GIF Banner Maker 1.4 kingaff Application Downloads 0 25-Feb-2007 12:48 AM


All times are GMT -8. The time now is 09:23 AM.

Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0

DMCA Policy

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228