Code: Select all
$results=mysql_query('SELECT * FROM `users`;');
while($row = mysql_fetch_array($results)){
$test=mysql_query('SELECT `id` FROM `scml_keys` where `id`='.$row['id'].';');
if(!$test){
mysql_query('INSERT INTO `scml_keys` (`id`) VALUES ('.$row['id'].');');
echo 'Adding '.$row['id'].' to keys.<br>';
}else{
echo 'Found: '.$row['id'].'<br>';
}
}
I am trying to use the script above to see if all of the id's from users exist in scml_keys and if it doesn't, add that id to scml_keys.
For some reason $test is always returning true, even if I empty the table completely. How should I challenge $test to make sure it returns false when an id isn't found?