I am trying to have the script pick a row from a table at random, and keep searching if it exists in another table.
The code might explain it better
do {
// get a random row from table A
$search = mysqli_query($db, 'SELECT * FROM `a` ORDER BY RAND() LIMIT 1');
// get the id
$row = mysqli_fetch_assoc($search);
$row_id = $row['id'];
// check table B to see if the row id exists
$check = mysqli_query($db, 'SELECT `id` FROM `b` WHERE `item` = "' . $row_id . '" LIMIT 1');
$result = mysqli_num_rows($check);
} while ($result === 1);
From my understanding, it should loop until it finds a song which exists in table A, but not B, and then move on, and I can use $row_id.
Now this works, but every so often it will return with a row that exists in table B
ORDER BY RANDis performance murder, do not use on large table, but for a small one its ok$result === 1means result must be an int, nottruenot"1"but1and only1, is possible you have duplicate data? this would also fail