An Ingenious Banner Rotation System, Part 3By Bill Graziano
In Part 2 we looked at creating an administration page to manage the various advertisements. In this part we'll look at displaying the ads!
I have a page called
BANNER_Display.asp which contains a subroutine called
This page executes a stored procedure called
spBANNERDisplay01 which returns one randomly selected
record from the
BANNER_Ads table. My code to select a record looks like this:
I use the SQL Server function
rand() to generate a random number. You can pass it a seed or have SQL
Server determine a seed for you. It will use the same seed for each random number requested inside a batch.
Since I only request one random number per batch I was ok using this approach. I multiply my random number times
WeightScaled and use this to select my record. If I had code running to implement
impression tracking I would insert a record into an impression tracking table right after the select. The
WeightScaled field has an index on it to improve performance of this query.
BANNER_Display.asp looks at the
AdType field and decides whether to display HTML or
build a linked image. That codes looks something like this:
Well, there you go. A simple, quick way to build a slightly improved Ad Rotator. I plan to add features to this
in the future including Advertisers, ad locations, impression and click tracking, impression and click caps
and or course, some way to track revenue. I just never seem to run out of features