This is some code that runs and updates some user accounts via cron. For some reason it only updates the first record in the set and none of the others after that. Code:
$sql = mysql_query("SELECT id,unit_production,peasants,total FROM users WHERE activated='1' AND disabled='0'");
$numrows = mysql_num_rows($sql);
while($row = mysql_fetch_assoc($sql)) {
$id = $row['id'];
$units = $row['unit_production'];
$peasants = $row['peasants'];
$total = $row['total'];
for($a=0;$a<sizeof($numrows);$a++) {
$newunits=$units+$peasants;
$total+=$units;
$sql = mysql_query("UPDATE users SET peasants='$newunits', total='$total' WHERE id='$id'");
}
}
if(!$sql) {
errorlog("Error adding units to user accounts: ".mysql_error());
} else {
$message.="Units successfully added to user accounts.\n";
}
When ever this code is ran I get:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in f:\apache\htdocs\war\unitprod.php on line 20
Anyone have any suggestions? or recommend a better way of updating the user accounts? The number of accounts could possibly reach 10,000+ at some point. Thanks for any help!