在UPDATE上计算新值

时间:2013-07-07 12:13:35

标签: php mysql

// open csv 
$handle = fopen("update.csv", "r");

// select cols
while (($data = fgetcsv($handle, 1000, ";")) !== false) {
$model = mysql_real_escape_string ($data[0]);
$price = mysql_real_escape_string ($data[5]);
$quantity = mysql_real_escape_string ($data[7]);
mysql_select_db("verradt33_develop", $link);

// replace comma with period and text with numbers
$price = str_replace(",", ".", $price);
$quantity = str_replace("JA", "10", $quantity);
$quantity = str_replace("NEE", "0", $quantity);

// execute
$result = mysql_query("UPDATE dev_product SET price='$price' , quantity='$quantity'     WHERE model='$model'")
or die(mysql_error());

以上代码有效。现在我想知道是否可以计算$price以排除增值税(21%)价格。

示例:

CSV提供1.99。但是我想在数据库中插入1.64461.99 / 121 x 100排除增值税)

1 个答案:

答案 0 :(得分:0)

只需添加/1.21

即可
UPDATE dev_product 
SET price = $price / 1.21, 
    quantity = $quantity 
WHERE model = '$model'