douli8428 2016-02-21 08:59
浏览 39

使用php从mysql中的单个表中过滤多个产品

i am trying to filter multiple products from database using php. i have check box in html page with 4 category,the values will be stored in a array on submit values post to php page , where data is filtered. see below example.

enter image description here

bellow is my html

<input class="le-checkbox" type="checkbox" name="filter1[]" value="<?=$bkey?>" /> <label><?=$bkey?></label>
<input class="le-checkbox" type="checkbox" name="filter2[]" value="<?=$bkey?>" /> <label><?=$bkey?></label>
<input class="le-checkbox" type="checkbox" name="filter3[]" value="<?=$bkey?>" /> <label><?=$bkey?></label>
<input class="le-checkbox" type="checkbox" name="filter4[]" value="<?=$bkey?>" /> <label><?=$bkey?></label>

values are stored in filter1[],filter2[],filter3[],filter4[]

in php

$filter1=$_POST['filter1'];
$filter2=$_POST['filter2'];
$filter3=$_POST['filter3'];

and also implode

i

f(isset($filter1)){

        $pbrand= implode(",",$filter1);

        }
    if(!empty($filter2)){

        $pcolor= implode(",",$filter2);

        }
        if(!empty($filter3)){

        $pfab= implode(",", $filter3);

        }

now check with mysql

$result = $dbh->prepare("SELECT * FROM products_list WHERE status='Available' AND brand IN (?) OR color IN (?) OR fabric IN (?)");
        //$result->bindValue(1, $status);
        $result->bindValue(1, $pbrand);
        $result->bindValue(2, $pcolor);
        $result->bindValue(3, $pfab);

its working fine when i select single checkbox from each category. when i check multiple checkbox from single catagory, its not working and also my condition status='Available' not working i don't understand why its not working

  • 写回答

1条回答 默认 最新

  • doujianwan7570 2016-02-21 09:07
    关注
    $result = $dbh->prepare("SELECT * FROM products_list WHERE status='Available' AND (brand IN (?) OR color IN (?) OR fabric IN (?))"
    

    brackets is need after AND

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大