"The age of the banner ad is dead" shouts a self-proclaimed online marketer. "Banner ads represent a bad return on investment" writes another. The truth of the matter is that banner ad's aren't dead, my friend. In this article Tim shows us how to create a banner management application that lets us add nifty MySQL-blobbed, two part drop-down banners to our sites. If you run your own site then you can't afford not to read this tutorial!
Make Your Own Cool Drop Down Ad's - The admin.php script (contd.) (Page 4 of 7 )
After adding a banner, a confirmation message will be displayed in the browser, linking back to the list of banners. By calling admin.php without any query string value for method, the ShowBanners function is called:
switch($_GET["method"]) { // Other options here default: ShowBanners(); }
ShowBanners simply connects to our MySQL database and retrieves the bannerID, title, numImps and numClicks field for each banner from the banners table and displays them in a list. The ShowBanners function also works out the click-thru rate for each banner as well. Here's what admin.php output after I added two banners to the database:
ShowBanners starts off by executing a SELECT statement against the banners table:
$result = @mysql_query("select bannerId, title, numImps, numClicks from banners order by title asc");
With the results from this select statement, a table containing rows of the banners is built. Dividing the number of clicks by the number of impressions and then multiplying that result by 100 works out the click-thru rate for each banner:
The click-thru rate of a banner is typically measured as a percentage compared to the number of impressions, so we use the number_format function to format the result with two decimal places.
If you noticed the screenshot of the ShowBanner function above, then you would've seen the "Remove" link next to each banner. The remove link points to admin.php?method=delete&bannerId=xxx, which means that the DeleteBanner function is called, passing in the bannerId query string as its only parameter:
function DeleteBanner($BannerId)
DeleteBanner connects to the database and executes an SQL DELETE command against the banners table, removing the banner whose bannerId field is $BannerId:
if(@mysql_query("delete from banners where bannerId = $BannerId")) { // Query OK, banner has been deleted ?> <h2>Banner Deleted</h2> Your banner has been successfully deleted a banner from the database. Use the link below to goto the list of banners. <br><br> <a href="admin.php">View Banners >></a> <?php } else { // Query failed ?> <h2>An Error Occured</h2> An error occured while trying to delete the selected banner database. Use the link below to try again. <br><br> <a href="javascript:history.go(-1)"><< Go Back</a> <?php }