Jump to content

Recommended Posts

The following code works, it provides me the SUM Amount of all the records in the database.  What i need to know is how to show a Line Balance.  for example

 

id message pay_amount  pay_balance

5  Paid        $500              $300              < - i can get this to show for all ID's as the balance ,

4  Debt      -$100            $-200            <- I need this line balance

3  Debt      -$100            $-100

2  Balance  0                      0   

 

 

Any Help is greatly appreciated.

 

Heres my code:

 

   $query = "SELECT * FROM payments WHERE propid = '$propid' ORDER BY id DESC ";
        $result = mysql_query($query);
        while($row = mysql_fetch_assoc($result))
	{
	    $pay_id		 	= $row['id'];
		$propertyid     = $row['propid'];
		$pay_message   		= $row['pay_message'];
		$pay_smessage 	    = substr($pay_message,0, 15);
		$pay_who 		= $row['pay_who'];
		$pay_date 		= $row['pay_date'];	
		$pay_amount		= $row['pay_amount'];	
		$pay_controller = $row['pay_controller'];						

		if($pay_controller == "-") {

			$fontcolor = "red";
		} 
		if($pay_controller == "+") {

		   $fontcolor = "black";
		}

        $query9 = "SELECT SUM(pay_amount) FROM `payments` WHERE propid = '$propid'"; 
		$result9 = mysql_query($query9);
        $sum = mysql_result($result9,0);
            $sum2 =  number_format($sum,2);




print"<tr  onMouseOver=\"this.bgColor = '#CEE3F6'\" onMouseOut =\"this.bgColor = '#FFFFFF'\">
<td onclick=\"window.alert('Amount: $pay_amount Message: $pay_message')\">$pay_id</td><td>$pay_smessage</td><td>$pay_date</td><td><font color=\"$fontcolor\">$$pay_amount</font></td><td>$sum2</td>

";
  }

 

 

Link to comment
https://forums.phpfreaks.com/topic/263347-line-calculations/
Share on other sites

Side comment: your table is a bit off and your signs are backwards (from what I can tell). Such a table normally looks more like

Balance: $300

ID | Message | Amount | New Balance
---+---------+--------+------------
5 | Paid    | -$500  | -$200
4 | Debt    |  $100  | -$100
3 | Debt    |  $100  |  $0

It starts off with an initial balance and changes for each transaction.

 

 

But that's irrelevant. For the initial problem, just do the math as you run through the results.

$pay_balance -= $pay_amount;

Link to comment
https://forums.phpfreaks.com/topic/263347-line-calculations/#findComment-1349640
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.