SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    309
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Is there any algorithm to make some ad display at random more often than others

    Hi,
    I have a table of advertisement with expiry date and location. Currently, I display ad at random base on userís location.

    In the near future, I want to add tier system in to my ad sale. It means the first tier ad should be displayed more often than the second tier, but I donít know how to control that.

    Is there any existing solution for my problem?

    Thank you,

  2. #2
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    309
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Anyone? Here's the code I've been done so far:
    Creating a table:
    Code:
    $mysqli->query("CREATE TABLE `ads` (
      `id` INT NOT NULL AUTO_INCREMENT,
      `uid` INT NOT NULL,
      `txt` TEXT NOT NULL,
      `date` DATE NOT NULL default '0000-00-00',
      `img` VARCHAR( 120 ) NOT NULL,
      `location` VARCHAR( 75 ) NOT NULL,
      `expiry` DATE NOT NULL default '0000-00-00',
    PRIMARY KEY ( `id` ),
    UNIQUE (
      `id`
      )
    ) ENGINE = INNODB CHARACTER SET UTF8 COLLATE utf8_general_ci
    ")
    or die("DB error!");
    Random with PHP:
    Code:
    SELECT id, uid, img, location, expiry
    FROM ads
    WHERE location = '$location' AND CURDATE() < expiry AND RAND()<(SELECT ((1/COUNT(*))*10) FROM ads)
    ORDER BY RAND()
    LIMIT 1
    Some one suggests I have to add some sort of percentage but I wasn't lucky with Google search.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,015
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    similar thread on (shock!) another forum yesterday...
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    309
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Thank you. Any added knowledge is good news. I'm now convinced that it is seriously problematic. I'll abandoned this until getting further information.

    Thank you again.

  5. #5
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    309
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I found a solution. This is nothing new. Here it is: http://www.kahunaburger.com/2008/10/...ds-from-mysql/


Bookmarks

Posting Permissions

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