显示错误mysqli_fetch_assoc()期望参数1为mysqli_result,给定布尔值

时间:2016-09-13 09:16:22

标签: php mysqli

我正在设置一个搜索按钮,用于显示高或低的产品,并通过品牌。 当我单击按钮时,我知道SQL有效,但它没有显示任何结果只是给出了这个错误:

  

警告:mysqli_fetch_assoc()期望参数1为mysqli_result,   在C:\ xampp \ htdocs \ alphacomponents.co.uk \ search.php中给出的布尔值   第51行

我已经运行var_dump ($sql);并显示字符串(59)" SELECT * FROM products WHERE deleted = 0 ORDER BY price ASC" 所以我知道SQL语句没问题,它只是不喜欢

之后的这个语句
$productQ = $db->query($sql);

这是我的代码:

<?php
require_once 'core/initial.php';
  include 'includes/head.php';
  include 'includes/navigation.php';


  $sql = "SELECT * FROM products";
  $cat_id = (($_POST['cat'] != '')?sanitize($_POST['cat']):'');
  if($cat_id == ''){
      $sql .= ' WHERE deleted = 0';
  }else{
    $sql .= " WHERE categories = '{$cat_id}' AND deleted = 0";
  }

  $price_sort = (($_POST['price_sort'] != '')?  
  sanitize($_POST['price_sort']):'');
  $min_price = (($_POST['min_price'] != '')?
  sanitize($_POST['min_price']):'');
  $max_price = (($_POST['max_price'] != '')?
  sanitize($_POST['max_price']):'');
  $brand = (($_POST['brand'] != '')?sanitize($_POST['brand']):'');
  if($min_price != ''){
    $sql .= " AND price >= '{$min_price}'";
  }
  if($max_price != ''){
    $sql .= " AND price <= '{$max_price}'";
  }
  if($brand != ''){
    $sql .= " AND brand = '{$brand}'";
  }
  if($price_sort == 'low'){
    $sql .= " ORDER BY price ASC";
  }
  if($price_sort == 'high'){
    $sql .= " ORDER BY price DESC";
  }


  $productQ = $db->query($sql);
  var_dump ($sql);
  $category = get_category($cat_id);
?>
<?php  include 'includes/leftsidebar.php'; ?>

<!-- Main content -->
<div class="col-md-8" id="productborder">
<div class="row">
  <?php if($cat_id != '') : ?>
 <h3 class="text-left"><?=$category['parent']. ' > ' .    
  $category['child'];?></h3>
  <?php else: ?>
    <h2 class="text-center">Alpha Components</h2>
  <?php endif; ?>
    <hr>
  <?php while($product = mysqli_fetch_assoc($productQ)) : ?>

0 个答案:

没有答案