[英]Concatenation of SQL query in PHP if statement
我正在尝试通过PHP if语句连接一个SQL查询,如下所示:
$sqlProdPage = "SELECT DISTINCT productpts.ProductID,product.ProductTitle,productsubtype.ProductSubtype,producttype.ProductType,product.ProductPrice,product.ProdDiscount,product.ProductImage,
product.ProductDescription,product.ProdFeatured,product.ProdQTY,product.ProdAddDesc
FROM productpts
INNER JOIN product ON productpts.ProductID=product.ProductID
INNER JOIN productsubtype ON productpts.ProductSubtypeID=productsubtype.ProductSubtypeID
INNER JOIN producttype ON productpts.ProductTypeID=producttype.ProductTypeID
WHERE product.Archive='0'";
$prodType_id=(($_POST['product'] != '')?sanitize($_POST['product']):'');
if(!empty($prodType_id)){
$sqlProdPage.= " AND ProductTypeID='{$prodType_id}'";//echo $prodType_id;die();
}
从我进行的故障排除中,问题是在级联SQL查询的if语句中的某个位置
$sqlProdPage.= " AND ProductTypeID='{$prodType_id}'"
谁能给我关于如何串联的建议?
但是内联37我遇到以下错误:
警告:mysqli_fetch_assoc()期望参数1为mysqli_result,在第37行的C:\\ xampp \\ htdocs \\ aresV2 \\ search.php中给出的布尔值
第36和37行:
$prodAvail = $db->query($sqlProdPage);
<?php while($product= mysqli_fetch_assoc($prodAvail)) : ?>
问题在于ProductTypeID
是在多个表中定义的,因此不确定应使用哪个表。
$sqlProdPage.= " AND productpts.ProductTypeID='{$prodType_id}'";
应该可以解决问题(假设它来自productpts
表)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.