PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
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";
Thank you
Last edited by geryatric on Sat Oct 17, 2009 1:32 pm, edited 2 times in total.
Thanks for the reply tasairis
That was a typo and I just corrected it .
having played around with it during the the day I think the problem is in the
mysql_fetch_array($result);
any thoughts ?