I want to sum of row & show the result in the same row as Remaining Column but i am getting same result (Sum of first row) in every row here is my PHP code
<?php
$sub = mysql_connect ("localhost", "root", "");
if (!$sub)
{
die('Could Not Connect:' .mysql_error());
}
mysql_select_db("tabsc",$sub);
if (!empty($_POST))
{
$sql= "INSERT INTO fund (dat, sour, condi, amount, disburse, othe, expenditure)
VALUES ('$_POST[dat]','$_POST[sour]','$_POST[condi]','$_POST[amount]','$_POST[disburse]','$_POST[othe]','$_POST[expenditure]')";
header('location: funding.php');
if (!mysql_query($sql, $sub))
{
die('Error' .mysql_error());}}
//start add sql column value on the top
$result = mysql_query('SELECT SUM(amount) AS amount FROM fund');
$row = mysql_fetch_assoc($result);
$sum = $row['amount'];
$result = mysql_query('SELECT SUM(disburse) AS disburse FROM fund');
$row = mysql_fetch_assoc($result);
$sumd = $row['disburse'];
$result = mysql_query('SELECT SUM(othe) AS othe FROM fund');
$row = mysql_fetch_assoc($result);
$sumo = $row['othe'];
$result = mysql_query('SELECT SUM(expenditure) AS expenditure FROM fund');
$row = mysql_fetch_assoc($result);
$sume = $row['expenditure'];
$remh=$sum-($sumd+$sumo+$sume);
//end add sql column value on the top
$resul=mysql_query("SELECT * FROM fund");
echo "<table border='1'>
<tr>
<th></th>
<th></th>
<th>Total</th>
<th>$sum</th>
<th>$sumd</th>
<th>$sumo</th>
<th>$sume</th>
<th>$remh</th>
<th></th>
<tr>
<th>Date</th>
<th>Source</th>
<th>Condition</th>
<th>Amount</th>
<th>Disburse</th>
<th>Other Payament</th>
<th>Expenditure</th>
<th>Remaining</th>
<th>Delete/Edit</th>
</tr>";
//Row Wise Sum (I think problem is here)
$result =mysql_query('SELECT id, SUM( amount + disburse + othe + expenditure) AS remaining FROM fund GROUP BY id');
$row = mysql_fetch_assoc($result);
$sumrem = $row['remaining'];
while ($row = mysql_fetch_array($resul))
{
echo '<tr>';
echo '<td>' .$row['dat'].'</td>';
echo '<td>' .$row['sour'].'</td>';
echo '<td>' .$row['condi'].'</td>';
echo '<td>' .$row['amount'].'</td>';
echo '<td>' .$row['disburse'].'</td>';
echo '<td>' .$row['othe'].'</td>';
echo '<td>' .$row['expenditure'].'</td>';
echo "<td>$sumrem</td>"; //Result will be into this columne
echo '<td><a href="delete.php? id='.$row['id'].'">Del</a> || <a href="edit.php? id='.$row['id'].'">Edit</a>';
echo '</tr>';
}
echo '</table>';
mysql_close($sub);
?>