<?php
$randd=rand(1,10);
while ($coord <> $randd) {
$randd=rand(1,10);
$used = mysql_query("SELECT coords FROM miscel WHERE (coords = '$randd')");
while ($row = mysql_fetch_array($used)) {
$used = ("$row[0]");
}
if ($randd <> $used) {
$coord = $randd;
}
}
?>
This works, but whenever it finds that $randd has already been used in the table, it displays an error. It changes the number, but it still displays the error =/. How can I get it to not display an error?
could the error be the syntax error from "$coord <> $randd" because i dont think $coord can be both less than $randd and greater than it at the same time.
It looks to me that the problem is because you redefine the $used variable. If you find a match, the $used variable get the row results, but then the next time through the while loop (since for all it knows, there may be other matches it has to fetch) it tries to issue a "mysql_fetch_array($used)" command, but $used no longer stores the query text.
Try either removing the while loop just so you do one fetch: