Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Super Moderator
    Join Date
    May 2002
    Perth Australia
    Thanked 110 Times in 108 Posts

    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)

  2. #2
    Regular Coder
    Join Date
    Mar 2008
    Thanked 9 Times in 9 Posts
    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

  3. #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,668 Times in 2,637 Posts
    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
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  4. #4
    Senior Coder Inigoesdr's Avatar
    Join Date
    Mar 2007
    Florida, USA
    Thanked 406 Times in 398 Posts
    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
    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts