php - 从表中选择 * 列 = 用户名不起作用
问题描述
我正在尝试在支付网关存在的网站上实施折扣代码,一切都很好,但是当我尝试根据促销代码获取折扣的百分比时,用户从数据库输入的内容不起作用,而不是收取折扣价,它收取全价,完全忽略折扣
这里的代码
$getcode = $getcode[1];
$user = $_SESSION['username'];
$total = $_SESSION['totprice'];
$sql6 = 'SELECT * from promocode where username="'.$user.'" and promo_code="'.$getcode.'" ';
$result6 = mysqli_query($con, $sql6);
while($row6 = mysqli_fetch_assoc($result6)) {
echo "Discount: " . $row6["discount"]. "<br>";
$discount =$row6["discount"];
$grandtotal= $total - (($discount * $total) / 100);
$publishable_key = "*******************";
$secret_key = "********************";
if(isset($_POST['stripeToken'])){
Stripe::setApiKey($secret_key);
$description = "Invoice #".rand(99999,999999999) ;
$amount = $grandtotal;
$user = $_SESSION['username'];
所以而不是
$amount = $total - (($discount * $total) / 100);
它给了我
$amount = $total;
由于某些原因
解决方案
您没有累积所有折扣。每次循环时,您只需将当前行的折扣应用于总计,覆盖您从前几行计算的内容。
初始化$grandtotal
为总数,然后每次都从中减去。
另外,你不应该允许很多折扣让总和低于 0。我在最后检查一下。
$grandtotal = $total;
while ($row6 = mysqli_fetch_assoc($result6)) {
echo "Discount: " . $row6["discount"]. "<br>";
$discount = $row6["discount"];
$grandtotal -= $total - (($discount * $total) / 100);
}
if ($grandtotal < 0) {
$grandtotal = 0;
}
推荐阅读
- excel - 对于 SAP GUI 脚本,你知道创建 SAP 作业的脚本是什么吗?
- javascript - 如何将普通数组转换为嵌套在父对象中的嵌套对象
- ruby-on-rails - Rails 5 在类中包含助手
- typescript - 将“vue-enterprise-boilerplate”转换为打字稿库时出现问题?
- node.js - 使用 nodemailer 通过 Handlebar 发送时模板图像未呈现
- ios - UITextDropDelegate willPerformDrop 没有被调用
- java - 如何在 jmeter 的 __groovy() 函数中执行 java 方法/函数?
- php - 致命错误:不能在第 38 行的 C:\xampp\htdocs\ov400\application\views\Useraccount\Userlist.php 中使用 stdClass 类型的对象作为数组
- c++ - 为什么 syslog 有两个不同的函数声明?
- python - 使用 python-vlc 仅在用户定义的开始和结束时间范围内播放视频