Interesting question. This might be better to be asked in the PERL/CGI forum, since it's really a program logic question.
I know this sounds like a stock answer, but it does depend on how you have the logic set up with.
I gather you are putting the ads into a table, and you want to set a priority. For a small number of ads, one way would be to create a "run" table and enter the ID of the ad the # of times of it's priority. Then, you pick a random number 1 to #max_entries_in_run_table and use that serve up the banner. Actually, this sort of look-up table idea is the basis of a preferred way of starting to serve up ads, since you separate the display characteristics from the ad characteristics.
I wrote one or two very, very long messages about this some time ago.
You want to have a table for the 'advertiser' information, you need a table for the "campaigns" and a table for the "ads". You also need to set up "zones" (spaces on your site) that an ad fits into.
You need to take the information and "compile" it into a run-table, in order to handle a request for an ad in a timely (real-time) fashion.
The less complex your advertising system (or site) is, the less need there is for a compiled run-table.
The need for the run-table is such:
The run table contains only "information about" an ad or banner and it's zone-availability. Your program says "I need an ad that fits x,y,z criteria" That is run against the run-table, and an some values pop up. These values are passed to the template/browser/script whatever, that then has enough information to make the call to display the right ad.
This also leaves a second level of abstraction or randomization available, if the data passed back to the calling function is a randomized data set, or script, then that script can be the one that actually pulls the banner from the specified pool (zone-pool) once that information has been calculated.
Does this make sense?
banner advertising can get to extremely complex and incredibly maddening degrees of functionality. That is why some programs are "Free" or $30, and others are $25,000. It's not all "performance" but how well the program can manage hundreds, or thousands of campaigns, zones and advertisers.
http://www.postcards.com FAQ:
http://www.postcards.com/FAQ/LinkSQL/