Requesting a random records in my database?

Discussion in 'PHP' started by traian1, Aug 7, 2007.

  1. #1
    How would i go about requesting a two random fields in my database?

    
    mysql_connect("database", "111", "222") or die(mysql_error());
    mysql_select_db("table") or die(mysql_error());
    
    
    $result = mysql_query("SELECT * FROM table'")
    or die(mysql_error());  
    
    $row = mysql_fetch_array( $result );
    
    
    $header = $row['title'];
    $description = $row['text'];
    
    
    
    PHP:
    I have a database of 1000+ records. I want to select two records randomly.
    Say to have a value of
    $header1 = header field in no 392
    $description1 = description in field no 392
    $header2 = header field in no 542
    $description2 = description in field no 542

    how would i go about doing this?
     
    traian1, Aug 7, 2007 IP
  2. xdimension

    xdimension Peon

    Messages:
    180
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    one easy way:
    SELECT * FROM table ORDER BY RAND() LIMIT 2
    Code (markup):
     
    xdimension, Aug 7, 2007 IP
  3. traian1

    traian1 Well-Known Member

    Messages:
    193
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    123
    #3
    Did you save me lots of programming or what?! THANK U!!!!
     
    traian1, Aug 7, 2007 IP