Jump to content

Help adding columns in a WHILE LOOP from MySQL DB


kpetsche20

Recommended Posts

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>";

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.