HTML
  Home arrow HTML arrow Page 6 - Make Your Own Cool Drop Down Ad's
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  
Moblin 
JMSL Numerical Library 
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? 
HTML

Make Your Own Cool Drop Down Ad's
By: Tim Pabst
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 18
    2002-05-20

    Table of Contents:
  • Make Your Own Cool Drop Down Ad's
  • How drop down ads work
  • The admin.php script
  • The admin.php script (contd.)
  • Viewing, expanding and collapsing a banner
  • Tracking the number of click-thrus
  • 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
     
     
    ADVERTISEMENT


    Make Your Own Cool Drop Down Ad's - Tracking the number of click-thrus


    (Page 6 of 7 )

    Remember back to the admin.php script where the number of impressions, click thru’s and click-thru rate is listed for each banner. As we already know, the number of impressions is incremented whenever the viewBanner function is called. Track.php on the other hand increments the number of click-thru's for each banner and redirects the user to the destination link for that banner, depending on whether or not they clicked on the top or bottom banner.

    Track.php starts by connecting to our MySQL database and incrementing the numClicks field for the selected banner:

    @mysql_query("update banners set numClicks = numClicks + 1 where bannerId = " . $_GET["bannerId"]);

    Remember that the banners ID is passed as the bannerId query string value, so that's why $_GET["bannerId"] is used in the SQL query. After the number of clicks has been incremented, it's a simple matter of determining if the user clicked on the top or bottom banner. This is accomplished by checking the img query string variable:

    // Redirect the user to the link
    if($_GET["img"] == "top")
    {
    // Get the link for the top banner
    $result = @mysql_query("select link1 from banners where bannerId = " . $_GET["bannerId"]);
    }
    else
    {
    // Get the link for the bottom banner
    $result = @mysql_query("select link2 from banners where bannerId = " . $_GET["bannerId"]);
    }


    Depending on which banner was clicked, we retrieve either the link1 or link2 field from the banners table. Once retrieved, we make sure that field was indeed returned and use the header function to redirect the user to that link:

    if($row = mysql_fetch_row($result))
    {
    header("Location: " . $row[0]);
    }


    Sending the binary image data
    As we saw earlier, the viewBanner function sets the src of each banner image to something like getbanner.php?bannerId=2&img=top. Getbanner.php connects to the database and retrieves the blob data for the banners image as well as its MIME type, depending on whether img is top or bottom:

    if($_GET["img"] == "top")
    {
    // Get the top image for the banner
    $result = mysql_query("select data1, type1 from banners where bannerId = " . $_GET["bannerId"]);
    }
    else
    {
    // Get the bottom image for the banner
    $result = mysql_query("select data2, type2 from banners where bannerId = " . $_GET["bannerId"]);
    }


    Once the image and MIME type are retrieved, it's simply a matter of calling the header function to set the type of output and then echoing the binary data to the browser, like this:

    if($row = mysql_fetch_row($result))
    {
    header("Content-type: " . $row[1]);
    echo $row[0];
    }


    If you want to test getbanner.php then you can fire up your browser and visit http://localhost/getbanner.php?bannerId=1&img=top, assuming that you have added a banner with admin.php and that the scripts are installed on your local machine.

    More HTML Articles
    More By Tim Pabst


     

    HTML ARTICLES

    - Tabular Database Forms with HTML
    - Using the Find Functions for HTML Database F...
    - Sorting for Database Forms with HTML
    - Edit and Other Database Form Functions with ...
    - More Database Form Functions with HTML
    - Database Form Functions with HTML
    - Using the HTML Table Element as a Recordset
    - Building Single Row Database Forms with HTML
    - Introduction to Database Forms with HTML
    - Another Look at Animation of Geographical Ma...
    - Animation of Geographical Map Regions
    - Changing and Moving Pictures with CSS
    - Clickable Geographical Map Regions
    - Gradient Creation with the HR Element
    - Text on HTML Images: Do it Yourself







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