ORDER BY RAND ** SQL Issue

Discussion in 'PHP' started by j0563, Mar 2, 2009.

  1. #1
    From everything I can tell, my syntax is right, but this is not working:

    $result3 = mysql_query("SELECT threeva FROM partthree ORDER BY RAND() LIMIT 7");
    $row3 = mysql_fetch_array($result3);
      echo $row3['threeva']."<br /><br />";
    Code (markup):
    The above will just pull 1 random value. There are about 20 values to choose from but it doesn't matter what I set the LIMIT as, it will only produce 1 result.

    Any suggestions?
     
    j0563, Mar 2, 2009 IP
  2. qualityfirst

    qualityfirst Peon

    Messages:
    147
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    0
    #2
    
    $result3 = mysql_query("SELECT threeva FROM partthree ORDER BY RAND() LIMIT 7");
    while ($row3 = mysql_fetch_assoc($result3){
    echo $row3['threeva'].'<br /><br />';
    }
    
    PHP:
     
    qualityfirst, Mar 2, 2009 IP
  3. j0563

    j0563 Guest

    Messages:
    153
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3

    THANKS a ton! Worked like a charm! +rep.
     
    j0563, Mar 2, 2009 IP
  4. qualityfirst

    qualityfirst Peon

    Messages:
    147
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Glad I could help. This will work with almost any mysql_query that needs to data from multiple rows to be outputted, btw.
     
    qualityfirst, Mar 2, 2009 IP