stvs Posted December 18, 2007 Share Posted December 18, 2007 I am trying to make a sales sheet print out listing the sales person and the amount they have sold, then at the bottom give me the overall total of sales that were done. Right now all I have been able to do is pull the sales person name and display each one of there sale amounts for any given week of the year. What I cannot figure out is how do I go about adding up the sales and displaying a total amount at the bottom. I have pasted the below code which currently selects the date range from the sales records and sorts them by the sales person. What I would like to know how to do is add up the total amount of sales and display it at the bottom. Can anyone give me a hand as in what is the right direction to go with this? $date1 = "$month1$day1$year1"; $date2 = "$month2$day2$year2"; $query = "SELECT * FROM payment_info WHERE chargeon1 between '$date1' and '$date2' order by sales_person"; $result = mysql_query($query) or die(mysql_error()); $num_rows = mysql_num_rows($result); echo " <b>$num_rows</b> results found for all sales between <b>'$date1'</b> and <b>'$date2'</b><br><br>"; while ($row = mysql_fetch_array($result)) { $sales_person = $row["sales_person"]; $total_amount = $row["total_amount"]; echo " <table> <tr> <td width=150> $sales_person </td> <td width=150> <td width=150> $total_amount </td> <td width=150> <td width=150> $chargeon1 </td> </tr> </table> ";} ?> Quote Link to comment Share on other sites More sharing options...
corbin Posted December 19, 2007 Share Posted December 19, 2007 Hmm you might want to look into mysql SUM (Google should come up with the manual page if you need it). Or, you could just do: $total = 0; while($row = mysql_fetch_array($result)) { $total += $r['total_amount']; //echo all teh stuff and what not } Quote Link to comment 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.