Math with mysql and php

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
aybra
Forum Commoner
Posts: 56
Joined: Sun Nov 24, 2002 12:52 am

Math with mysql and php

Post by aybra »

OK, hers my next big simple problem, I cant for the life of me figure out how to make $outstanding calculate down the table till eventully equelling 0...

how it is done rignt now it will do the math for each line individual, but not as a solid string... any tips?

Code: Select all

<?php
	$querya = 'SELECT * FROM `duane` ORDER BY `date` DESC LIMIT 0, 30';
        $result1 = mysql_query($querya, $connection) or die('error making querya');

?>
<table width="100%" border="3"> 
... 
<tr>
<td>Amount Paid</td>
<td>Date Paid</td>
<td>WithStanding</td>
</tr>

<?php 
while ($row = mysql_fetch_assoc($result1)) { 
   $paid = $rowї"payment"];  
   $payday = $rowї"date"];
   $outstanding = 1700 - $rowї"payment"];
      echo '<tr><td>', 
            $paid, '</td><td>', 
            $payday, '</td><td>', 
            $outstanding, '</td></tr>'; 
            } 
?> 
... 
<input type="submit" name="Submit" value="Submit">
</table>

Thanks.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You want $outstanding to not be reset each time the while loop is run? If so then this might help:

Code: Select all

<?php  
$outstanding = 1700;
while ($row = mysql_fetch_assoc($result1)) {  
   $paid = $rowї'payment'];   
   $payday = $rowї'date']; 
   $outstanding -= $rowї'payment']; 
   echo '<tr><td>',  
       $paid, '</td><td>',  
       $payday, '</td><td>',  
       $outstanding, '</td></tr>';  
}  
?>
Mac
aybra
Forum Commoner
Posts: 56
Joined: Sun Nov 24, 2002 12:52 am

Post by aybra »

wow... COOL thanks man.

8O :D :)
Post Reply