Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tax

Status
Not open for further replies.

elemental

Programmer
Mar 17, 2001
33
0
0
CA
I've got a shopping cart app which calculates the total price for a number of items. I want it to add in the sales tax (in this case 15%) but when I write the code and test it, it doesn't. Could you guys check it out, as I'm stumped and need this by tomorrow. Here's the code. Thanks
<?php

// display full cart

// album detail...

$a_query = &quot;SELECT c.cart_id,c.quantity,pg.product_group_title,f.format_description,&quot;;
$a_query .= &quot;pc.product_code_id,pc.product_code_price &quot;;
$a_query .= &quot;* CASE WHEN ISNULL(s.special_percentage) OR s.start_date>CURDATE() OR s.end_date<CURDATE() &quot;;
$a_query .= &quot;THEN 1 ELSE (100-s.special_percentage)*.01 END AS price FROM product_codes pc &quot;;
$a_query .= &quot;LEFT JOIN product_groups pg USING (product_group_id) &quot;;
$a_query .= &quot;LEFT JOIN formats f ON f.format_id=pc.format_id &quot;;
$a_query .= &quot;LEFT JOIN carts c ON pc.product_code_id=c.product_code_or_event_id &quot;;
$a_query .= &quot;LEFT JOIN specials s ON pg.product_group_id=s.product_group_or_event_id &quot;;
$a_query .= &quot;WHERE c.session_id='$s_id' AND c.item_type_id=1&quot;;
$a_result = mysql_query($a_query)
or die(&quot;<h3>*Server Error*</h3><p>Please try again later.</p>&quot;);

$albums = 0;
$album_total = 0;
$line = 0;

if(mysql_num_rows($a_result) == 0)
echo &quot;<tr><td colspan=\&quot;4\&quot; align=\&quot;center\&quot;>[NO ALBUMS SELECTED]</td></tr>\n&quot;;
else
{
while($a_row = mysql_fetch_assoc($a_result))
{
$c_id = $a_row[&quot;cart_id&quot;];
$quantity = $a_row[&quot;quantity&quot;];
$price = $a_row[&quot;price&quot;];
$tax = 0.15;
$tax++;//Tax is now worth 1.15
$code = $a_row[&quot;product_code_id&quot;];
$title = stripslashes( $a_row[&quot;product_group_title&quot;] );
$format = stripslashes( $a_row[&quot;format_description&quot;] );

$item_amount = $quantity * $price * $tax;

$albums += $quantity;
$album_total += $item_amount;

$bgcolor = $line % 2 == 1?&quot;&quot;:&quot; bgcolor=\&quot;#EEEEEE\&quot;&quot;;
$button_class = &quot;changeCart&quot; . ($bgcolor == &quot;&quot;?&quot;1&quot;:&quot;2&quot;);
$line++;

echo &quot;<tr><td class=\&quot;cart\&quot; align=\&quot;right\&quot; nowrap=\&quot;nowrap\&quot;$bgcolor>\n<form action=\&quot;cart.php\&quot; &quot;;
echo &quot;method=\&quot;POST\&quot; onsubmit=\&quot;return checkConfirm(this);\&quot;>\n&quot;;
echo &quot;<input type=\&quot;text\&quot; name=\&quot;quantity\&quot; size=\&quot;2\&quot; value=\&quot;$quantity\&quot; />\n&quot;;
echo &quot;<input type=\&quot;hidden\&quot; name=\&quot;item\&quot; value=\&quot;$c_id\&quot; />\n&quot;;
echo &quot;<input type=\&quot;hidden\&quot; name=\&quot;code\&quot; value=\&quot;$code\&quot; />\n&quot;;

if( isset($HTTP_POST_VARS[&quot;last_page&quot;]) )
$last_page = $HTTP_POST_VARS[&quot;last_page&quot;];
else
$last_page = $HTTP_REFERER;
echo &quot;<input type=\&quot;hidden\&quot; name=\&quot;last_page\&quot; value=\&quot;$last_page\&quot; />\n&quot;;

echo &quot;<input type=\&quot;submit\&quot; class=\&quot;$button_class\&quot; name=\&quot;update\&quot; value=\&quot;Change\&quot; &quot;;
echo &quot;onclick=\&quot;setButtonValue(this);\&quot; &quot;;
echo &quot;title=\&quot;Click here to change item quantity.\&quot; /><br />\n&quot;;
echo &quot;<input type=\&quot;submit\&quot; class=\&quot;$button_class\&quot; name=\&quot;delete\&quot; value=\&quot;Delete\&quot; &quot;;
echo &quot;onclick=\&quot;button='delete';formSubmit=true;\&quot; title=\&quot;Click here to delete this item.\&quot; /></form></td>&quot;;
echo &quot;<td class=\&quot;cart\&quot;$bgcolor>$format -- $title</td>\n&quot;;
echo &quot;<td class=\&quot;cart\&quot;$bgcolor align=\&quot;center\&quot;>\$&quot;;
printf(&quot;%.2f&quot;, $price);
echo &quot;</td>\n<td class=\&quot;cart\&quot;$bgcolor align=\&quot;right\&quot;>\$&quot;;
printf(&quot;%.2f&quot;, $item_amount);
echo &quot;</td></tr>\n&quot;;
}
echo &quot;<tr><td colspan=\&quot;3\&quot; align=\&quot;right\&quot;><b>$albums ALBUMS:</b></td><td align=\&quot;right\&quot;><b>\$&quot;;
printf(&quot;%.2f&quot;, $album_total);
echo &quot;</b></td></tr>\n&quot;;
}
 
Well, it adds the total based on quantity and price but doesn't add the tax in. I'm a wee bit new at some of this.
TIA
erik
 
yes and I don't know why.....It adds the $ quantity and $price but seems to not do the tax calculation....I'm thinking I missed something....but not sure what....
 
Status
Not open for further replies.

Similar threads

Replies
2
Views
23

Part and Inventory Search

Sponsor

Back
Top