Page 1 of 1

Math with mysql and php

Posted: Sun Nov 24, 2002 10:20 am
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.

Posted: Mon Nov 25, 2002 2:47 am
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

Posted: Mon Nov 25, 2002 6:11 am
by aybra
wow... COOL thanks man.

8O :D :)