Jump to content

Adding Up Total Amount Of Sales


stvs

Recommended Posts

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

?>

Link to comment
Share on other sites

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
}

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.