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

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.