Jump to content

Recommended Posts

hello. I am trying to calculate 7% sales tax inside of this script, however, every time I do it, it never works. It is either exponentially adding the tax, multiplying the price by 10, then adding tax,etc....and I am not sure what I was doing wrong. any ways, I would like it to calculate tax for any item that has the category of "artist" or "retail". can anyone help me out here?

 

<?php
$sql1= mysql_query("SELECT * FROM cart where cart_id='".$cid."' AND product123 !='' ORDER BY id DESC ");
 while($row1 = mysql_fetch_array($sql1)){
  $price = $row1['price'];
  $product = $row1['product123'];
  $id = $row1['id'];
  $qty = $row1['quantity'];
  $category = $row1['category'];


$price1 = $price * $qty;
$total =  $price1 + $total;
 }
?>

Link to comment
https://forums.phpfreaks.com/topic/274782-calculating-tax/
Share on other sites


  <?php
$sql1= mysql_query("SELECT * FROM cart where cart_id='".$cid."' AND product123 !='' ORDER BY id DESC ");
while($row1 = mysql_fetch_array($sql1)){
$price = $row1['price'];
$product = $row1['product123'];
$id = $row1['id'];
$qty = $row1['quantity'];
$category = $row1['category'];
if($category="artist"){
$price2= $price*'.07';
$price1 = $price * $qty;
$total =  $price1 + $total + $price2;
}
$price1 = $price * $qty;
$total =  $price1 + $total; 
}
?>

 

this is one way I tried just addding onto artist category, but it still did it for all other categories as well, and it multiplied by two, then added the tax to the end.

Link to comment
https://forums.phpfreaks.com/topic/274782-calculating-tax/#findComment-1413927
Share on other sites

= is assignment. == is comparison.

 

You also need to move the $price1 part BEFORE your if, and the total part AFTER. 

 

Go read each line and say what it does in English. It's obvious why you're getting duplicate amounts. You're telling it to add and multiply twice.

 

Also, '.07' is a string. Try using a NUMBER.

Edited by Jessica
Link to comment
https://forums.phpfreaks.com/topic/274782-calculating-tax/#findComment-1413930
Share on other sites

Not sure what you were doing there mate, think you need o lay off the crack but this should work. Not tested

 

<?php


$sql1= mysql_query("SELECT * FROM cart where cart_id='".$cid."' AND product123 !='' ORDER BY id DESC ");


while($row1 = mysql_fetch_array($sql1)){
$price = $row1['price'];
$product = $row1['product123'];
$id = $row1['id'];
$qty = $row1['quantity'];
$category = $row1['category'];


 if($category="artist"){
  //add the tax, you guys are lucky only getting charged 7%!!!!!
  $price = $price + ( $price * 0.07 );
 }


$price1 = $price * $qty;
$total =  $price1 + $total; 
}
?>

Link to comment
https://forums.phpfreaks.com/topic/274782-calculating-tax/#findComment-1413965
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.