kpetsche20 Posted February 21, 2008 Share Posted February 21, 2008 The tax is tracked by invoice #. Each invoice number has two separate entries in the taxtable. I'm trying to select the entries from the table and add them together then display them under "Tax". However with my current code it's only displaying the amount of 1 row in the table. not the total of all rows with the same invoice #. You can view the output at http://floridafuelinjection.com/reports/name_total_nontax/ echo"<table width=800 border=1> <tr> <td><b>Name</b></td> <td><b>Total w/ out tax</b></td> <td><b>Non-Taxable</b></td> <td><b>Taxable</b></td> <td><b>Tax</b></td> </tr>"; $cur_bal = "0"; $grabnamefromtable = mysql_query("SELECT * FROM name_total"); for($x=0; $x < mysql_num_rows($grabnamefromtable); $x++) { $arrayMadeFromNameTotaltb = mysql_fetch_array($grabnamefromtable); $UseNameToGetTaxOrNoTax = mysql_query("SELECT * FROM tax WHERE type = 'total'"); $test = mysql_fetch_array($UseNameToGetTaxOrNoTax); echo "<tr> <td>".$arrayMadeFromNameTotaltb['name']."</td> <td>".$arrayMadeFromNameTotaltb['price']."</td>"; if($arrayMadeFromNameTotaltb['name'] == $test['Name']) { if($test['Sales Tax Code'] == 'Non-Taxable Sale') { echo "<td>".$test['Amount']."</td> </tr>";} else { $qerey = mysql_query("SELECT * FROM taxamount WHERE Num = ".$test['Num'].""); if(mysql_num_rows($qerey) > 1 ) { $qerey2 = mysql_fetch_assoc($qerey); $gery = $cur_bal + $qerey2['Amount']; } echo " <td> Taxable </td> <td>".$test['Amount']."</td> <td>".$gery."</td> </tr>";} } } echo " <tr> <td></td> </tr></table>"; ?> Link to comment https://forums.phpfreaks.com/topic/92348-help-adding-columns-in-a-while-loop-from-mysql-db/ Share on other sites More sharing options...
Barand Posted February 21, 2008 Share Posted February 21, 2008 If you want a total for each inv number you need a query like SELECT invoice_number, SUM(taxA + taxB) as Tax FROM tablename GROUP BY invoice_number Link to comment https://forums.phpfreaks.com/topic/92348-help-adding-columns-in-a-while-loop-from-mysql-db/#findComment-473167 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.