understanding weighting...

Discussion in 'Programming' started by Acecool, Jul 3, 2007.

  1. #1
    I understand weighting for two things..

    if (rand(0, 100) > $chance)
    show the lesser value ad
    else
    show the higher paying ad...


    But, I want to implement this for more than 2 ads from a database..

    right now I use:
    SELECT id, weight FROM acms_ads WHERE area="header" ORDER BY RAND() * ( 1 / weight ) LIMIT 1

    BUT, if the weight is 0, it always shows, or if the weight is a lot higher than the others it sometimes shows it all the time...

    Anyone have any ideas on how to improve this to use a %, default is 10, 20 shows twice as much as everything else, 100 ALWAYS shows

    Josh
     
    Acecool, Jul 3, 2007 IP