The goto statement was mainly - if any - used for error processing: in a long list of statement, each of them being able to trigger an error, a jump (goto) was made near the bottom of the function to skip all the remaining statements, and run a common error processor at the end of the function.
But nowadays, even PHP has exception handling, thus the use of goto is even less justified.
Fix the problem as mentioned
In your case, you can implement a simple algorithm to perform the equivalent function
do {
$rnumber = rand(1, 10);
$queryresult = $mysqli->query("SELECT uniquerandomcolumn FROM tbldata WHERE uniquerandomcolumn =" . $rnumber);
} while ($queryresult->num_rows > 0);
having the risk of being in an infinite (or very long) loop...
Room for improvement
Since the number of tries is limited (1 .. 10), it would be better to
- try all numbers from 1 to 10 (maximum) once without repetition
- randomly (eg 7 2 3 9 ...)
ie, perform a maximum of 10 tries, and exit if the row does not exist or if all 10 tries have been done. To try randomly from 1 to 10, use the shuffle function to shuffle randomly an array of 1 to 10 elements.
$tries = array();
for ($i=1 ; $i<=10 ; $i++) $tries[] = $i; // create an array (1,2,3,4,5...)
shuffle ($tries); // shuffle the array, eg now $tries is (8,2,9,1,7...)
$index = 0; // start with first element of $tries
do {
$rnumber = $tries[$index++];
$queryresult = $mysqli->query("SELECT uniquerandomcolumn FROM tbldata WHERE uniquerandomcolumn =" . $rnumber);
} while ($queryresult->num_rows > 0 && $tries < 10);
This way you try randomly all 10 possible values, not more.
After the while add
if ($queryresult->num_rows < 1) {
// found a non existing number: $tries[$index-1]
}
else {
// all 10 numbers exist in the DB...
}
to deal with the two conditions.