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 = $_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();
}
}
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.
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.
Thanks.