random database select

Discussion in 'PHP' started by promotingspace.net, Jul 13, 2007.

  1. #1
    Hi
    I want to display random articles in my homepage from "article" table in my database.
    Also would like to display the title of 5 random articles there
    how can I do that?
    thanks
     
    promotingspace.net, Jul 13, 2007 IP
  2. pophysis

    pophysis Peon

    Messages:
    44
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $sql = "SELECT * FROM articles ORDER BY RAND() LIMIT 1";
    PHP:
     
    pophysis, Jul 13, 2007 IP
    ansi likes this.
  3. Fl1p

    Fl1p Active Member

    Messages:
    511
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Just increase the LIMIT to 5 from pophysis code if you want to display 5 random articles.
     
    Fl1p, Jul 13, 2007 IP
  4. promotingspace.net

    promotingspace.net Peon

    Messages:
    361
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Now what if i want to display random "article of the day"?
    The above code will output a different articles each time the homepage is loaded. but what if I want to have only 1 article displayed in a single day?
     
    promotingspace.net, Jul 15, 2007 IP