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..

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.