Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-15-2008, 02:14 AM   PM User | #1
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,898
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
Banner weighting ?

It seems as though I should have by now but I have never made an ad/banner rotator~
My main question is how would I apply a banner weighting system ... what would be the logic for that?

e.g. I want ads marked as `class 1` to show far more often than those in `class 2,3` etc but still keep some random element.

All ad data is kept in a db which I can change since I am in the early stages of development, any pointers appreciated.
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Old 05-15-2008, 02:24 AM   PM User | #2
peteyb383
Regular Coder

 
Join Date: Mar 2008
Posts: 118
Thanks: 3
Thanked 9 Times in 9 Posts
peteyb383 is an unknown quantity at this point
Using PHP, select a random number from 0-5

Then use Case/If statements to tell what to do depending on the random number value.

To "weigh" an ad, simply show it whenever the number is 0, 1, 2, or 3 and the 2nd ad will show on 4 and the 3rd ad on 5
__________________
Petey

View my Blog and Support my Mission!
peteyb383 is offline   Reply With Quote
Old 05-15-2008, 03:37 AM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Sup firepages, been awhile since I've run into you on here
Being the king of over-complication myself, I'd write a priority queue if I were in a language like C#, and apply an algorithm that essentially allots an additional 10-15% probability for each level of the numeric queue. I guess the same logic can be applied to php as well, I'd simply keep the priority value within the database, say 1 through 5 (if we are looking at the 10-15% increase), and write a simple algorithm to drill down the priority numbers and select from that. Then randomly choose from the remaining results.

Does that make sense at all, or did I just confuse you as much as I just confused myself :P
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 05-15-2008, 11:08 PM   PM User | #4
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Quote:
Originally Posted by firepages View Post
All ad data is kept in a db which I can change since I am in the early stages of development, any pointers appreciated.
If it's MySQL(and not a huge table, as RAND() can be kinda slow) you can use
Code:
SELECT * FROM `table` WHERE 1 ORDER BY RAND() * `weight`
`weight` would be a pre-determined value that you have set individually in each column or hard-coded in your script.
Inigoesdr is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:28 PM.


Advertisement
Log in to turn off these ads.