Questo è il classico caso in cui si DEVE usare il while, non il for.
Inoltre, alla funzione check() devi anche passargli il valore da controllare come argomento.
Codice PHP:
public function check($x,$y)
{
$exists = mysql_query("SELECT * FROM _utente WHERE x = $x AND y = $y LIMIT 1");
if ( mysql_num_rows ( $exists ) == 1 )
{
return true;
}
else
{
return false;
}
}
Codice PHP:
public function set()
{
$this->x = rand(9, 10);
$this->y = rand(9, 10);
while ( $this->check( $this->x, $this->y ) == TRUE )
{
$this->x = rand(9, 10);
$this->y = rand(9, 10);
}
echo "È false
";
}
Questo ovviamente va in loop se nel DB hai già tutte le combinazioni possibili (4 combinazioni con i valori che hai previsto per x ed y), ma per il resto dovrebbe funzionare.
Altra cosa: i campi x ed y devono essere dichiarati come INT nel DB, altrimenti devi metterci gli apici attorno a $x ed $y