在php中的多个复选框过滤器中从数据库中获取数据

时间:2015-07-16 09:08:45

标签: php mysql checkbox

我想通过复选框点击从数据库中获取数据,这里我的代码适用于单个复选框,但它显示" mysql_fetch_assoc()期望参数1是资源,布尔值在"多个复选框上的错误, 这是我的代码,

if(isset($_POST['submit'])){
if(!empty($_POST['filter'])) {
$valid=true;

$filtering=$_POST['filter'];
       $query_str=" WHERE ";
    foreach ($filtering as $value){
      if ($value=="Arsh Nagar"){
         $query_str .="stylish_name='Arsh nagar'";
      }
      else if ($value=="Padma"){
         $query_str .="stylish_name='Padma'";
      }
      else if ($value=="Kajal Yadav"){
         $query_str .="stylish_name='Kajal Yadav'";
      }
       else if ($value=="Shweta"){
         $query_str .="stylish_name='Shweta'";
      }
       else if ($value=="Harshil"){
         $query_str .="stylish_name='Harshil'";
      }
      $query_str .=" OR ";
    }
    $query_str=substr($query_str,0,-5);
    $sql="SELECT * FROM createdlook ".$query_str;

}
else{
$filter_err="Please Select atleast 1 stylish";
$valid=false;
}
}

 if($valid)
    {

    $result=mysql_query($sql); //here is the error generated
    $images = array();
    $index = 0;

    while($row = mysql_fetch_assoc($result)) // loop to give you the data in an associative array so you can use it however.
    {
         $images[$index] = $row;
         $index++;
    }

我认为这是一些查询问题。如果查询中有任何错误,请解决它

0 个答案:

没有答案