Mysql Update
Posted: Sat Oct 17, 2009 4:17 am
I am developing 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, could some one advise me on the update query.
Thank you
All is working fine only the table wont update, could some one advise me on the update query.
Code: Select all
if(isset($_POST['$lotto_id'])){$lotto_id = $_POST['$lotto_id'];}
if(isset($_POST['$income'])){$income = $_POST['$income'];}
$query = "SELECT lotto_id, balance FROM lotto_member WHERE lotto_id =$lotto_id";
$result = mysql_query($query) or die;
$num_res = mysql_num_rows($result);
$num_rows = mysql_num_rows($result);
for ($i=0; $i<$num_res; $i++){
$row = mysql_fetch_array($result);
// existing Balance in table
$balance = $row["balance"];
// Divide the new amount by the number of members
$split = $income / $num_rows;
// add the two together
$member_total = $split + $balance ;
// test it
echo "$member_total <br>";
}
// update the DB
$query = "UPDATE lotto_member SET balance='$member_total' WHERE lotto_id =$lotto_id";