LIKE查询在php代码中返回空行

时间:2017-05-12 12:46:29

标签: php mysql

我有3个表的数据库。我正在尝试访问与查询一起使用的所选按钮的商店名称:

SELECT sm.*,
        GROUP_CONCAT(c.cat_name) as Category_Names,
        GROUP_CONCAT(c.cat_id) as Category_ID 
FROM `store_manufacture` sm , Categories c, Store_Category sc 
where sm.sm_id = sc.store_id 
  AND c.cat_id = sc.cat_id 
  AND sm.sm_brand_name LIKE "H%" 
GROUP BY sm.sm_id

输出

enter image description here

但是当我应用查询显示所选字母数据时。它没有显示商店名称。

PHP

$selected_val='';
if(isset($_POST['getValue'])){
    $selected_val = $_POST['getValue'];
    $sql='SELECT sm.*,
            GROUP_CONCAT(c.cat_name) as Category_Names,
            GROUP_CONCAT(c.cat_id) as Category_ID 
      FROM store_manufacture sm , Categories c, Store_Category sc 
      where sm.sm_id = sc.store_id 
        AND c.cat_id = sc.cat_id 
        AND sm.sm_brand_name LIKE"'.$selected_val .'% 
      GROUP BY sm.sm_id"';

    $sm=mysqli_query($con,$sql);
    while ($row = mysqli_fetch_array($sm,MYSQLI_ASSOC)){
        $sm_id = $row['sm_id'];
        $name = $row['sm_brand_name'];
        $cat_ids = $row2['Category_ID'];
  ?>
 <a href="store_profile.php?name=<?php echo $name ?>&cat_id=<?php echo $cat_ids ?>"
  class="list-group-item"><?php echo $name ?></a>
  </div>
<?php
    }
}

1 个答案:

答案 0 :(得分:1)

您的通配符后错过了双引号

AND sm.sm_brand_name LIKE"'.$selected_val .'%"   <--