ASP
  Home arrow ASP arrow Page 9 - Make Revenue With Your Own Banner Manageme...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Make Revenue With Your Own Banner Management System
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 7
    2001-11-01

    Table of Contents:
  • Make Revenue With Your Own Banner Management System
  • Adding the banners
  • Saving the banners
  • The ASP to add the banner
  • The ASP to add the banner (contd)
  • Listing the banners
  • Deleting a banner
  • Displaying and tracking banners, impressions and click-thrus
  • The code in detail
  • Handling the banner clicks
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Iron Speed
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Make Revenue With Your Own Banner Management System - The code in detail


    (Page 9 of 11 )

    Let's start with the function declaration:

    function GetBanner()

    dim objConn

    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


    This function is responsible for the retrieval and display of a banner at random from our database. Firstly, we declare a new database connection and recordset. After this, we set the virtual path for the location of our banners folder in the strBanner_VirtualPath variable. Lastly, we open a connection to our database and set the ActiveConnection of our recordset object to point to this connection.

    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


    This next part of our code is where the random number generation takes place. Firstly, we use our recordset object to get a count of the number of records in our banners table. The query we have used (select count(*) from banners) returns a table with one field containing one value. If we executed this query using query analyser when we had three banners in our table, we would achieve this result:

    [None]

    After we store the return value into the variable intNumBanners, we run a quick check to make sure that there is at least one banner in our table. If there isn't, we exit the function and return nothing.

    Now comes the random banner generation. First, we call the Randomize function which basically tells our ASP engine this: "When we call the Rnd() function, make sure we get a random number every time". It sounds confusing, but really, it isn't. Then we use the Rnd() function to generate a random integer between 1 and the number of records in our database (in my case, 3), followed by closing our recordset object.

    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


    Because we closed our recordset object previously, we must open it again. However, this time we select all the rows in the banners table as our query. Because we're using a recordset with a dynamic cursor (objRS.CursorType = adUseDynamic), we have the ability to move to any row in that recordset. objRS.Move intRandom uses our randomly generated number as the row to move to. So If we generated a random number of 3, we would move to the third row in our recordset (remember that recordsets are like a zero-based array, so we'd be moving to row number three but the row would have an index of 2).

    The last line is used to build the HTML string that we will output in our browser. The code uses simple anchor and image tags to display our banner with a link. Notice the URL in the anchor tag (bannerclick.asp?bannerId=" & objRS("bannerId")). This is the next and final page that we will discuss. It's the page that handles the addition of click-thrus and re-directs the user to the URL that corresponds to that particular banner. More on that later, though.

    objConn.Execute "UPDATE banners SET bannerImpressions =

    bannerImpressions + 1 WHERE bannerId = " & objRS("bannerId")

    objConn.Close



    set objConn = nothing

    set objRS = nothing



    end function


    The final part of our GetBanner function uses our connection object to increase the impression count for the randomly selected banner, and frees up the memory used by our connection and recordset objects.

    I understand the function, now what?

    So, now that we've stored our GetBanner() function in bannercode.asp, how do we display the banners on our Website? It's a simple matter of adding two lines of code to any existing ASP page. Lets look at an example:

    <!-- #INCLUDE file="bannercode.asp" -->

    <html>

    <head>

    <title> My Test Banner </title>

    </head>

    <body>

    <%=GetBanner()%>

    </body>

    </html>


    As you can see from the example above, we simply use an SSI (Server-Side include) to reference the file that holds our GetBanner function. Then we simply call this function with either the <%= GetBanner() %> method or <% Response.Write GetBanner() %> method.

    In the next and final part of the tutorial, we'll create the bannerclick.asp page that handles the click-thrus and re-directions when a banner is clicked from our site.

    More ASP Articles
    More By Mitchell Harper


     

    ASP ARTICLES

    - Central Scoreboard with Flash and ASP
    - Calorie Counter Using WAP and ASP
    - Creating PGP-Encrypted E-Mails Using ASP
    - Be My Guest in ASP
    - Session Replacement in ASP
    - Securing ASP Data Access Credentials Using t...
    - The Not So Ordinary Address Book
    - Adding and Displaying Data Easily via ASP an...
    - Sending Email From a Form in ASP
    - Adding Member Services in ASP
    - Removing Unconfirmed Members
    - Trapping HTTP 500.100 - Internal Server Error
    - So Many Rows, So Little Time! - Case Study
    - XDO: An XML Engine Class for Classic ASP
    - Credit Card Fraud Prevention Using ASP and C...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway