Hi all
I have a system that im working on the the code works fine it, but theres a part thats giving me issues below is the code that loops through the number of records in the table and generates the same number of update queries with the random numbers like so:
generate.php code
<?php
include ('themes/config.php');
function genRandomString() {
$length = 6;
$characters = '023456789';
$string .= $characters[mt_rand(0, strlen($characters) -1 )];
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}
return $string;
}
$q = mysql_query("SELECT * FROM details")or die(mysql_error());
$r = mysql_num_rows($q);
for($i = 0; $i<$r; $i++){
$random_string = genRandomString();
echo '<br>';
echo $k = "UPDATE details SET password = '$random_string'";
$result = mysql_query($k);
}
?>
and here is the result
UPDATE details SET password = '9235270'
UPDATE details SET password = '599206'
UPDATE details SET password = '3565609'
problem 1) the database is only picking and updating the last query for all the rows which is:UPDATE details SET password = '3565609'
i want it to update all 3 rows (all the rows when increased) with the different values.
problem 2) i want to apply a prfix e.g. ZX124873.
Please let me know if you need more information or clarification any kind of help will be appreciated. Thanks in advance.