geryatric Posted October 24, 2009 Share Posted October 24, 2009 I am trying to develope a script which will take a number from the url divide it by the number of members in a table add it with the balance already on the table and save the total. Then update the table with the new total. All is working fine only the table wont update as I want it to . The update is acting as if its updating one record , so if I have 5 records each with a different starting balance they all end up the same after the up date , hope this makes sense. if(isset($_POST['lotto_id'])){$lotto_id = $_POST['lotto_id'];} if(isset($_POST['income'])){$income = $_POST['income'];} $result = mysql_query( "SELECT balance FROM lotto_member WHERE lotto_id ='$lotto_id'"); while($row=mysql_fetch_array($result)){ $num_rows = mysql_num_rows($result); // existing Balance in table $balance = $row["balance"]; // divide Income by the number of members $divide_it = $income / $num_rows; // add the two together $new_total = $divide_it + $balance; //Update the DB $sql_update = "UPDATE lotto_member SET balance ='$new_total' WHERE lotto_id= $lotto_id"; mysql_query($sql_update) or die(mysql_error()); } THANK YOU Link to comment https://forums.phpfreaks.com/topic/178880-up-date-from-an-array/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.