It changes the first record only.
Code: Select all
//Printing out values before the change
$query="SELECT * FROM test";
$result=mysql_query($query) or die(mysql_error());
while($row=mysql_fetch_array($result))
{
echo"ID " . $row['id'] . ": " . $row['the_rand'] . "<br>";
}
$i=1;
while($i<=$totalRows_Recordset1)
{
$id = $row_Recordset1['id'] ;
$new_rand=rand();
//echo "UPDATE test SET the_rand=$new_rand WHERE the_rand=$i...<br>";
mysql_query("UPDATE test SET the_rand=$new_rand WHERE ID=$id") or die(mysql_error());
$i++;
$id = $row_Recordset1['id'] ;
}
echo "-------------------------------<br>";
$query="SELECT * FROM test";
$result=mysql_query($query) or die(mysql_error());
while($row=mysql_fetch_array($result))
{
echo"ID " . $row['id'] . ": " . $row['the_rand'] . "<br>";
}
ID 1: 1696848048
ID 2: 241
ID 3: 18
-------------------------------
ID 1: 681325506
ID 2: 241
ID 3: 18
When I change "WHERE ID=$id" to WHERE ID=$i I get random numbers.
But that would not work if the id's are 50,51,52
I could really use some advice and am I approaching my goal the right way? I was thinking about runnig this daily to shuffle the cards so to speak.
Thanks! -Scott