如何使用PHP中搜索字段的多个输入搜索mysql表?

时间:2017-01-24 09:22:26

标签: php mysql

我正在开发一个PHP / Mysql项目,我已经对数据表进行了过滤搜索。

但是我意识到所有过滤器只接受一次输入。我想使用逗号在单个字段中提供许多输入。那怎么办呢?

我的过滤器的SS,下面附带的表单代码和Sql查询。

So when the search is done, the result is shown in the table on right side blank space

<?php
 $res = false;

 if(isset($_REQUEST['submit'])){
    $FirstName=$_POST['FirstName'];
    $LastName=$_POST['LastName'];
    $Function=$_POST['Function'];
    $State=$_POST['State'];
    $Country =$_POST['Country'];
    $Website =$_POST['Website'];
    $sql=" SELECT * FROM hz WHERE FirstName like '%".$FirstName."%' AND LastName LIKE '%".$LastName."%' AND Function LIKE '%".$Function."%' AND State LIKE '%".$State."%' AND Country LIKE '%".$Country."%' AND Website LIKE '%".$Website."%'";
    $q=mysqli_query($con, $sql);
}
else{
  $res = true;
}
?>

表单代码:

<form method="post" class="search">
    <table width="200">
    <td>
       <tr><input class="form__input" type="search" name="FirstName" placeholder="First Name" value="<?php if(isset($FirstName)) echo $FirstName;?>" /></tr>
       <tr><input class="form__input" type="search" name="LastName" placeholder="Last name" value="<?php if(isset($LastName)) echo $LastName;?>" /></tr><BR>
<!--<tr><input class="form__input" type="search" name="Company Standard Name" placeholder="Company Name" value="<?php if(isset($Company)) echo $Company;?>" /></tr><BR>
        <tr><input class="form__input" type="search" name="Job Title" placeholder="Job Title" value="<?php if(isset($Job)) echo $Job;?>" /></tr><BR> -->
        <tr><input class="form__input" type="search" name="Function" placeholder="Function" value="<?php if(isset($Function)) echo $Function;?>" /></tr><BR>
       <tr><input class="form__input" type="search" name="State" placeholder="State" value="<?php if(isset($State)) echo $State;?>" /></tr><BR>
<!--       <tr><input class="form__input" type="search" name="Zip Code" placeholder="Zipcode" value="<?php if(isset($Zip)) echo $Zip;?>" /></tr><BR> -->
       <tr><input class="form__input" type="search" name="Country" placeholder="Country" value="<?php if(isset($Country)) echo $Country;?>" /></tr><BR>
       <tr><input class="form__input" type="search" name="Website" placeholder="Website" value="<?php if(isset($Website)) echo $Website;?>" /></tr><BR>    
       <tr><input type="submit" name="submit" value=" Search " class="button"/></tr>
    </td>
    </table>
</form>

Ps:$con = mysqli_connect("host","user","password", "databasename");

0 个答案:

没有答案