Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何确保$"$总折扣“报价”;也基于站点url_Php_Mysql - Fatal编程技术网

Php 如何确保$"$总折扣“报价”;也基于站点url

Php 如何确保$"$总折扣“报价”;也基于站点url,php,mysql,Php,Mysql,我有多个网站使用相同的数据库表进行折扣。但是,当if语句为true时,无论使用哪个网站,return部分都会返回第一个url的值。我如何确保$“$折扣”也基于网站url list($discount_offer_on_totals) = mysqli_fetch_row(mysqli_query($connect,"select discount_offer from orders_discounts")); if ( $total < $discount_o

我有多个网站使用相同的数据库表进行折扣。但是,当if语句为true时,无论使用哪个网站,return部分都会返回第一个url的值。我如何确保$“$折扣”也基于网站url

list($discount_offer_on_totals) = mysqli_fetch_row(mysqli_query($connect,"select discount_offer from orders_discounts")); 
    if ( $total < $discount_offer_on_totals ) {
    return "Order total must be $ ". $discount_offer_on_totals." or more to qualify for discount!";
    }
list($discount\u offer\u on\u totals)=mysqli\u fetch\u行(mysqli\u query($connect,“从订单中选择折扣\u offer\u折扣”);
如果($total<$折扣\优惠\总计){
return“订单总额必须为$”、“$折扣”、“$折扣”、“$折扣”或更多才能享受折扣!”;
}

您可以在查询中使用where条件

$stmt = mysqli_prepare($connect, "SELECT discount_offer FROM orders_discounts WHERE url = ? ");
mysqli_stmt_bind_param($stmt, "s", $_SERVER['SERVER_NAME']);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$row = mysqli_fetch_row($result);

可以在查询中使用where条件

$stmt = mysqli_prepare($connect, "SELECT discount_offer FROM orders_discounts WHERE url = ? ");
mysqli_stmt_bind_param($stmt, "s", $_SERVER['SERVER_NAME']);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$row = mysqli_fetch_row($result);

使用参数化查询。将
$\u SERVER
变量(或任何相关变量)注入查询是个坏主意。@Andrei,请建议使用参数化查询进行改进。我不是编程方面的专家,但是学习谢谢你的建议@Andrei。我已更新答案。请使用参数化查询。将
$\u SERVER
变量(或任何相关变量)注入查询是个坏主意。@Andrei,请建议使用参数化查询进行改进。我不是编程方面的专家,但是学习谢谢你的建议@Andrei。我已经更新了我的答案。