gagards200 Posted September 26, 2010 Share Posted September 26, 2010 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.. Quote Link to comment https://forums.phpfreaks.com/topic/214456-how-to-get-the-sum-inside-the-while-loop/ Share on other sites More sharing options...
Pikachu2000 Posted September 26, 2010 Share Posted September 26, 2010 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/214456-how-to-get-the-sum-inside-the-while-loop/#findComment-1115951 Share on other sites More sharing options...
gagards200 Posted September 26, 2010 Author Share Posted September 26, 2010 Tnks Mr. Pickachu....it really helps...thanks for your help... Quote Link to comment https://forums.phpfreaks.com/topic/214456-how-to-get-the-sum-inside-the-while-loop/#findComment-1115954 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.