title: I need to pull data from 6 random records but I'm having a bit of trouble
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/9945691/doing-a-while-loop-to-get-10-random-results">Doing a while / loop to get 10 random results</a>  </p>
  </blockquote>
  
  
  
  <p>I'm making a website which people can upload funny pictures they take or make. Each time the home page is loaded, a random picture/record is displayed from the MySQL database onto the page. This is done with...</p>
  
  <pre><code>$filename = mysql_fetch_row(mysql_query("SELECT filename FROM pictures ORDER BY RAND() LIMIT 1"));
  echo $filename[0];
  </code></pre>
  
  <p>This would echo a random pictures file name onto the page. Something like <code>funny_cat</code>. But then I need the file type so that I can echo out the image onto the page. Like this...</p>
  
  <pre><code>while ($record = mysql_fetch_array(mysql_query("SELECT * FROM pictures WHERE p='$p'"))) {
      $filetype = $record["filetype"];
  }
  echo "&lt;img src=\"picture/".$filename[0].".".$filetype."\" /&gt;";
  </code></pre>
  
  <p>All is good. </p>
  
  <p>Now here's the bit I'm struggling on. I'm wanting to display 6 other random smaller pictures onto the page. So I need to get 6 random records and echo the <code>filename</code> and <code>filetype</code> for each record. The thing that needs considering is I can only get random records with the technique I used above due to the way the database is set up. How could I do this?</p>
  
  <p>If there is anything you're unsure about please say and I'll try explain. Also, please explain your solutions. Thanks!! <strong><em>:-)</em></strong></p>