Is there a better solution to this loop?
<p>I'm making a website which basically displays a random image but I need a better bit of code of what I have at the moment. I'm hoping someone could come up with a better solution.</p>

<pre><code>$p = $_GET["p"];
$qrynumrows = mysql_query("SELECT * FROM pictures");
$numrows = mysql_num_rows($qrynumrows);

if (!isset($p)) {
    $randid = rand(1, $numrows);
    $qryrecord = mysql_query("SELECT * FROM pictures WHERE id='$randid'");

    while ($row = mysql_fetch_array($qryrecord)) {
        $rowp = $row["p"];
        $rowremove = $row["remove"];
    }

    if ($rowremove == 1) {
        header("Location: http://www.lulzorg.com/");
        exit();
    }
    else {
        header("Location: http://www.lulzorg.com/?p=$rowp");
        exit();
    }       
}
</code></pre>

<p>So what it's doing is picking a random record from the database but it needs to check whether the record is allowed. The bit of code works fine but I'm sure there's a better/faster way to do it.</p>

<p>If $rowremove is equal to 0 then the image is allowed to display. If $rowremove is equal to 1 then the image is NOT allowed to display.</p>

<p>Thanks.</p>
