PHP Code:
$armysys = $vbulletin->db->query_read("SELECT strike_action, defense_action, spy_rating, sentry_rating, attack_soldiers, defense_soldiers, untrained_soldiers, spies, sentries FROM " . TABLE_PREFIX . "armysys");
while ($armysys = $vbulletin->db->fetch_array($armysys)) {
$rank = ( ($armyinfo['strike_action'] + $armyinfo['defense_action'] + $armyinfo['spy_rating'] + $armyinfo['sentry_rating']) / (4) );
$gold = ( ($armyinfo['attack_soldiers'] * 15) + ($armyinfo['defense_soldiers'] * 15) + ($armyinfo['untrained_soldiers'] * 5) + ($armyinfo['spies'] * 10) + ($armyinfo['sentries'] * 10) );
$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "armysys SET rank = '$rank', gold = gold + '$gold'");
}
I have tried so many variations of code that my brain hurts. I need this code to update the field rank in armysys with $rank (the average of the 4 fields you see in the variable). As well it neess to update the field gold with $gold (the sum of the fields in the variable). Depending on what I change it sometimes doesn't do anything, but it usually just updates ever row witht he same info.