Q: php adding amount in rows I want to add the rows that is being query in database. There is an amount paid, previous balance, new balance.. I want the previous balance to be added by paid amount.
Num|pay|old|new

1  |100|500|600

2  |120|600|720

3  |200|720|920

4  |300|720|920

5  |350|720|920

6  |500|720|920

The database query has data of amountPaid (pay), previous balance (old), new balance (new), but the data in column(new) is wrong.I want to correct it in forloop.Is there a way to help me in this? to get the column(new) value is 
column(pay)100  + column(old)500 = column(new)600.
the column(new) in number two will be put in column(old)600 then added by column(pay)120 is equal to column(new)720 and so on.
Hope you can help me in this...

A: I suppose you are adding the amounts when user submits it
1) Use mysql UPDATE clause in order to change the value in the coloumns
2) use while loop to get the previous value selecting it with a specific id which I suppose you have in your table 
3) add it with a new value and update the new amount coloumn 
PHP
<?php
     $id=$_POST['id'];
     $amount=$_POST['amount'];

    include("connection.php"); 
    $sql="SELECT * FROM  `tablename` WHERE  `user_id` ='$id'";
    $res=mysql_query($sql);
    $row=mysql_fetch_array($res){


            $t2 = $row['previous_amount'];
            $t3=$t2+$amount;
            $sql="UPDATE  `bank`.`tablename` SET `new_amount' = '$t3'";
        }
?>

