Jump to content

[SOLVED] Sum of one variable - can it be done?


Recommended Posts

I'm trying to figure this out.  I've managed totals, percentages, and subtracting.  But this I can't seem to figure:

 

$getPayments = "SELECT * FROM jos_bid_payments WHERE salenum = ".$catnum." AND userid = ".$clientID."";
$resPayments = mysql_query($getPayments) or die(mysql_error());	

	while ($rowsPaid = mysql_fetch_array($resPayments)) {

		$payment = $rowsPaid['pay_method'];
		$amount = $rowsPaid['amount'];

		if ($amount > 0) {

			echo $payment.": £".number_format($amount,2)."<br />";

		}

	}

 

Some results will have multiple amounts, depending on payment methods.  These are all returned by $amount.  How can I get the total of all $amounts per person?  Obviously these are displayed per $clientID, but I really have no clue how to total them up... ???

Thanks for that, but it doesn't quite work :

 

In the DB I have two payments for an item, one of 2000.00 and another of 500.25 (to make sure decimals are carried through).

 

The output I get now seems to create a sum for all results held...???

 

I'll look into seeing if I can split it further.

 

 

SOLVED IT!!!!

 

I needed to have the individual amounts as well as a running total of payments made.  Clients may pay part on a card, the rest in a bank transfer.  This is for items from a few hundred pounds to a few hundred thousand pounds...

 

To see how I did it :

 

$getPayments = "SELECT * FROM jos_bid_payments WHERE salenum = ".$catnum." AND userid = ".$clientID."";
		$resPayments = mysql_query($getPayments) or die(mysql_error());	

		$total_payments = 0;

		while ($rowsPaid = mysql_fetch_array($resPayments)) {

		$payment = $rowsPaid['pay_method'];
		$amount = $rowsPaid['amount'];
		$total_payments += $rowsPaid['amount'];

		if ($amount > 0) {

			echo $payment.": £".number_format($amount,2)."<br />";

		}

		}

 

So now I can echo each result in the while loop and echo a total outside of the loop.  And it works.  I'm so chuffed.  Thanks for your help and pointers.

 

Rich

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.