如何制作大表格?

时间:2015-06-18 06:55:01

标签: php search

我想制作一个包含9个搜索字段的大表单(带有php / sql的html)。

今天,我使用Case When Then。

但是有9个领域,有很多组合

例如,当我搜索5个字段时。

如果有(如果没有则为空),并且在执行查询后,我会返回该字段。

if (!empty($_REQUEST['Liasse']))        {

    $Liasse=$_REQUEST['Liasse'];    
}
if (empty($_REQUEST['Liasse']))     {

    $Liasse=null;   
}


$Query="SELECT * FROM type where

         case 



    when :Liasse is not null and :Designation_du_composant_fr is null and :Item is null and :Categorie is null
    then Liasse=:Liasse

    when :Designation_du_composant_fr is not null and :Item is null and :Liasse is null and :Categorie is null
    then Désignation_du_composant_fr=:Designation_du_composant_fr

    when :Item is not null and :Designation_du_composant_fr is null and :Liasse is null and :Categorie is null
    then Item=:Item

    when :Categorie is not null and :Designation_du_composant_fr is null and :Item is null and :Liasse is null
    then Catégorie=:Categorie

    when :Categorie is not null and :Designation_du_composant_fr is not null and :Liasse is null and :Item is null
    then Catégorie=:Categorie and Désignation_du_composant_fr=:Designation_du_composant_fr 

    when :Categorie is not null and :Liasse is not null and :Designation_du_composant_fr is null and :Item is null
    then Catégorie=:Categorie and Liasse=:Liasse 

    when :Categorie is not null and :Item is not null and :Designation_du_composant_fr is null and :Liasse is null
    then Catégorie=:Categorie and Item=:Item 


    when :Item is not null and :Liasse is not null and :Designation_du_composant_fr is null and :Categorie is null
    then Item=:Item and Liasse=:Liasse

    when :Categorie is not null and :Designation_du_composant_fr is not null and :Item is not null and :Liasse is null
    then Catégorie=:Categorie and Désignation_du_composant_fr=:Designation_du_composant_fr and Item=:Item

    when :Categorie is not null and :Liasse is not null and :Item is not null and :Designation_du_composant_fr is null
    then Catégorie=:Categorie and Liasse=:Liasse and Item=:Item

    when :Designation_du_composant_fr is not null and :Liasse is not null and :Item is not null and :Categorie is null
    then Désignation_du_composant_fr=:Designation_du_composant_fr and Liasse=:Liasse and Item=:Item

    when :Categorie is not null and :Designation_du_composant_fr is not null and :Liasse is not null and :Item is null
    then Catégorie=:Categorie and Désignation_du_composant_fr=:Designation_du_composant_fr and Liasse=:Liasse

    when :Categorie is not null and :Designation_du_composant_fr is not null and :Liasse is not null and :Item is not null
    then Catégorie=:Categorie and Désignation_du_composant_fr=:Designation_du_composant_fr and Liasse=:Liasse and Item=:Item

    end";  

有更快的方法吗? 谢谢:))

1 个答案:

答案 0 :(得分:0)

搜索时可以使用

MATCH (something) AGAINST ('some words' IN BOOLEAN MODE)