Php 在折扣价格和显示后价值方面有困难。
因此,我想按存储在$discountPercent变量中的百分比对$cost变量进行折扣。我尝试过多种方法,但都不管用。此外,我在我的索引页面上有一个选择菜单,每当我选择一个国家时,它在我的“displayinfo”页面上显示为1。。。我太糊涂了,快把我逼疯了Php 在折扣价格和显示后价值方面有困难。,php,Php,因此,我想按存储在$discountPercent变量中的百分比对$cost变量进行折扣。我尝试过多种方法,但都不管用。此外,我在我的索引页面上有一个选择菜单,每当我选择一个国家时,它在我的“displayinfo”页面上显示为1。。。我太糊涂了,快把我逼疯了 <?php include 'includes/connect.php'; if(isset($_POST['submit'])) { $name = $_POST['f_name']." ".$_POST['l
<?php
include 'includes/connect.php';
if(isset($_POST['submit'])) {
$name = $_POST['f_name']." ".$_POST['l_name'];
$sl1 = $_POST['sl1'];
$sl2 = $_POST['sl2'];
$country = $_POST['country'];
$county = $_POST['county'];
$team = $_POST['team'];
$size = $_POST['size'];
$quantity = $_POST['quantity'];
if(isset($_POST['town'])) {
$town = $_POST['town'];
} else {
$town = "N/A";
}
function get_cost($size, $quantity) {
if($size == "S" || $size = "XS") {
$jerseyCost = 45;
} else if($size == "M" || $size = "L" || $size = "XL") {
$jerseyCost = 50;
}
$cost = $jerseyCost * $quantity;
return $cost;
}
$cost = get_cost($size, $quantity);
function check_discount_percent($cost) {
if($cost > 100 && !($cost > 250)) {
return 10;
}
else if($cost > 250) {
return 25;
} else {
return "Not applicable to receive discount.";
}
}
$discountPercent = check_discount_percent($cost);
function get_total_cost($cost, $discountPercent) {
if($discountPercent === 0){
$discountedPrice = $cost / 100 * $discountPercent;
return $cost - $discountedPrice;
} else {
return $cost;
}
}
$totalCost = get_total_cost($cost, $discountPercent);
if($country == "Ireland") {
$deliveryTime = "3 days";
} else if($country == "United States" ) {
$deliveryTime = "3 weeks";
} else if($country = "United Kingdom" || "France" || "Italy" || "Spain" || "Germany" || "Portugal" || "Switzerland" || "Denmark" || "Iceland") {
$deliveryTime = "1 week";
} else {
$deliveryTime = "2 - 6 weeks";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ajax Project | Cian Tiernan</title>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<header>
<h3> Ajax Project </h3>
<h4 id="home"><a href="index.php">Home</a></h4>
</header>
<div class="wrapper">
<h2 class="details"> Your order details!</h2>
<h3> Name </h3>
<p><?=$name?></p>
<h3> Street Line 1 </h3>
<p><?=$sl1?></p>
<h3> Street Line 2 </h3>
<p><?=$sl2?></p>
<h3> Country </h3>
<p><?=$country?></p>
<h3> County </h3>
<p><?=$county?></p>
<h3> Town </h3>
<p><?=$town?></p>
<h3> Team </h3>
<p><?=$team?></p>
<h3> Size </h3>
<p><?=$size?></p>
<h3> Quantity </h3>
<p><?=$quantity?></p>
<h3> Items Cost </h3>
<p> €<?=$cost?></p>
<h3> Discount Percentage </h3>
<p><?=$discountPercent?>%</p>
<h3> Total Cost </h3>
<p>€<?=$totalCost?></p>
<div id="map">
<iframe height="300px" width="45%" src="https://www.google.com/maps?z=4&f=q&output=embed&q=<?=$county?>"></iframe>
<h4>Delivery Time</h4>
<p><?=$deliveryTime?></p>
</div>
<a class="top" href="#"><h2>Back to top</h2></a>
</div>
</body>
</html>
Ajax项目| Cian Tiernan
Ajax项目
您的订单详情!
名称
街道1号线
街道2号线
国
县
镇
团队
大小
量
项目成本
欧元
折扣率
%
总成本
欧元
在函数get_total_cost中,仅当$折扣百分比为零时才应用折扣,这是没有意义的。只有当$折扣百分比>0时,才能应用它。或者,你也可以一直使用折扣,即使是0%。比如:
function get_total_cost($cost, $discountPercent) {
$discountedPrice = $cost / 100 * $discountPercent;
return $cost - $discountedPrice;
}
我建议你看看get\u total\u cost()
实际上做了什么!或者更确切地说,它没有做什么!这包括你对你的系统做一些基本的调试own@RiggsFolly这是转载。哦,好的,谢谢。我想“==”会检查它是否是整数。这就是为什么在它旁边放一个整数0你知道为什么我的国家显示为1吗?