Jump to content

how to get the sum inside the while loop


gagards200

Recommended Posts

Hello Guys can anybody help me to get the sum or total of the Net Salary in the below loop?

 

while($row = mysql_fetch_array($result))

  {

 

  echo "<td>" . "<font face='Arial' size='2'>" . $row['Employee_Name'] . "</td>" . "</font>";

  echo "<td>" . "<font face='Arial' size='2'>" . $row['Basic_Salary'] . "</td>". "</font>";

  echo "<td>" . "<font face='Arial' size='2'>" . $row['Total_Salary'] . "</td>". "</font>";

  echo "<td>" . "<font face='Arial' size='2'>" . $row['Gross_Salary'] . "</td>". "</font>";

  echo "<td>" . "<font face='Arial' size='2'>" . $row['Net_Salary'] . "</td>". "</font>";

  echo "<td>" . "<font face='Arial' size='2'>" . $row['Date_Covered'] . "</td>". "</font>";

    echo "</tr>";

  }

 

Here I want to display the total of all the Net Salary that the while loop display from the database....

I did like this but it doesn't work.............

                $total =$row['Net_Salary'];

$ftotal= $total + $total++;

 

Any idea guyz please help me, I am new here and I expect the php freak will help me in this problem..

You mean display the sum of them after the while loop has finished, right?

 

$total = 0;
while($row = mysql_fetch_array($result))
  {
  echo "<td>" . "<font face='Arial' size='2'>" . $row['Employee_Name'] . "</td>" . "</font>";
  echo "<td>" . "<font face='Arial' size='2'>" . $row['Basic_Salary'] . "</td>". "</font>";
  echo "<td>" . "<font face='Arial' size='2'>" . $row['Total_Salary'] . "</td>". "</font>";
  echo "<td>" . "<font face='Arial' size='2'>" . $row['Gross_Salary'] . "</td>". "</font>";
  echo "<td>" . "<font face='Arial' size='2'>" . $row['Net_Salary'] . "</td>". "</font>";
  echo "<td>" . "<font face='Arial' size='2'>" . $row['Date_Covered'] . "</td>". "</font>";
  echo "</tr>";
  $total += $row['Net_Salary'];
}
echo "<tr><td colspan=\"6\">Total of Net salaries: $total</td></tr>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.