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>"; ?> Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.