got another question...
I have the following while loop working:
$activityreport = "SELECT $fieldname FROM $table WHERE QuoteID=$quoteid";
$activity = mysql_query($activityreport) or die(mysql_error());
while($data = mysql_fetch_array($activity)){
$amount = $data[$fieldname];
if($amount>0 && $table != 'OptionFees'){
$amountc = abs($amount);
}
elseif($amount>0 && $table == 'OptionFees'){
$amountd = abs($amount);
}
elseif($amount<0 && $table == 'OptionFees'){
$amountc = abs($amount);
}
else{
$amountd = abs($amount);
}
$totald = $totald + $amountd;
$totalc = $totalc + $amountc;
echo "<tr><td class='description'>$table</td>
<td class='debit'>".money_format('%(#10n', $amountd)."</td>
<td class='credit'>".money_format('%(#10n', $amountc)."</td></tr>";
}
My issue is that $totald and $totalc are ending up with just the results from the last trip through the while loop, not the total of all trips as desired.
If it weren't for the IF statements breaking down $data[$fieldname], I could just use $total += $data[$fieldname], but the breakdown is important. As you can see, I'm using this to create a table which will display GL accounts and their respective debits and credits for a journal entry. The lines for each account display perfectly, but the total just show a repeat of the last line.
Any help would be very, very much appreciated!
mysql_*functions in new code. They were removed from PHP 7.0.0 in 2015. Instead, use prepared statements via PDO or MySQLi. See Why shouldn't I use mysql_* functions in PHP? for more information.