What I want to do is update empty fields in my database with random ID#. I have a script I am using to generate the $random variable.
I have it in a Do While Loop.
The flaw in my logic seems to be that the code is updating all empty fields at the same time with the same $random variable. How do I get it to update the fields one at a time with different random codes?
here is the code I am working with....
<Start code>
<?php require_once('../Connections/testdb.php'); ?><?do {$random= ""; srand((double)microtime()*1000000);
$block = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $block .= "0123456789";
for($i = 0; $i < 10; $i++) { $random .= substr($block,(rand()%(strlen($block))), 1); }
mysql_select_db($database_testdb, $testdb);$query_username = "SELECT username FROM users WHERE users.userid = ''";$username = mysql_query($query_username, $testdb) or die(mysql_error());$row_username = mysql_fetch_assoc($username);$totalRows_username = mysql_num_rows($username);
mysql_select_db($database_testdb, $testdb);$query_IDupdate = "UPDATE users SET users.userid = '$random' WHERE users.userid = ''";$IDupdate = mysql_query($query_IDupdate, $testdb) or die(mysql_error());
echo $totalRows_username;echo $IDupdate;echo ("<br>$random");
} while ($totalRows_username != 0);
mysql_free_result($username);?>
</End Code>