根据选择mysql php更新总价

时间:2011-10-11 12:35:37

标签: php mysql

你好我希望有人可以帮助我。我需要知道如何编写一个查询,这将允许我根据燃料数量选择添加一个值。

例如,用户选择100升,然后加总5英镑,或者如果他们选择500升,则加15英镑等。

以下是我目前用于计算每升价格的代码。

// show price
        $fuelPriceQuery = sprintf("SELECT `Price` FROM fuel_price WHERE FuelType = '%s' LIMIT 1",
                    mysql_real_escape_string($_POST['fueltype']));

        $fuelPriceResult = mysql_query($fuelPriceQuery);
        $price           = mysql_fetch_array($fuelPriceResult, MYSQLI_ASSOC);

        echo 'The Price Today is £'.($_POST['qtylitres'] * $price['Price']);
        echo "<br />";
        echo "For " . ($_POST['qtylitres']) . " Litres of " .($_POST['fueltype']);

echo "<br />" . "<br />";

if(mysql_num_rows(mysql_query("SELECT * FROM subscribe WHERE Email = '".mysql_real_escape_string($_POST['inputEmail'])."'")))
{
     echo "Thanks but we already have your email";
}   
else
{

1 个答案:

答案 0 :(得分:1)

通过此代码段扩展您的代码,如果我理解你的话,它应该完全符合您的要求。

[...]
if($_POST['qtylitres'] >= 100)
  $fee = 5;
if($_POST['qtylitres'] >= 500)
  $fee = 15;

echo 'The Price Today is £'.(($_POST['qtylitres'] * $price['Price'])+$fee);
[...]