#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Location
    Atlanta, GA
    Posts
    269
    Rep Power
    14
    I am trying to pull articles from my db at random on my site. Like for instance for a certain month I will have 20 articles in the db, and would like to pull 3 randm links to the articles at random, so everytime a user loads my hoome page different content will be provided, so it seems fresh. Any thoughts??
    thanks again.

    ------------------
    trops.
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4476
    One thought...

    SELECT * FROM your_table ORDER BY RAND() LIMIT 3

    or...since ORDER BY RAND() is only available after a certain version...

    SELECT *,RAND() AS temp_col ORDER BY temp_col LIMIT 3

    Hope that helps...it's in the manual, by the way....

    ---John Holmes...

    ------------------
    *************************************************************
    * The manual can probably answer 90% of your questions...
    *
    * PHP Manual. www.php.net/manual
    * MySQL Manual: www.mysql.com/documentation/mysql/bychapter
    *************************************************************
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Location
    Atlanta, GA
    Posts
    269
    Rep Power
    14
    Thanks for the help. I have a book on PHP, and it talks about mt_rand but didnt explain it very well. Ill give it a try. I was hoping you would reply, it seems like you know ALOT of this stuff, and I am having trouble.

    Thanks again, Ill let you know how it turns out.

    ------------------
    trops.
  6. #4
  7. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4476
    mt_rand() is a PHP function. PHP also has a rand() function. MySQL has a RAND() function also. I capitalize it just to show the difference, it doesn't have to be all caps. I just want you to understand that you're using a MySQL function in a SELECT statement, it has nothing to do with PHP. There are plenty of other functions you can use in your SELECT statements, too. Check the manual.

    ---John Holmes...
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Location
    Atlanta, GA
    Posts
    269
    Rep Power
    14
    i am an idiot.
    hehe
    thanks.

    ------------------
    trops.

IMN logo majestic logo threadwatch logo seochat tools logo