2016-12-04 4 views
0

私はチェックボックスを使って製品をフィルタリングしようとしていますが、1つのチェックボックスの値しか表示できません。 2をクリックすると、最初のチェックボックスの値のみが表示されます。2つのチェックボックスフィルタ以上の結果を表示

これはhtmlです:

<form action="busqueda.php" method="post"> 
    <input type="checkbox" name="especias" id="especias" <?php if($_POST[ 'especias']){ ?>checked="checked"<? } ?>> 
    <span class="cbx">Especias</span><br> 
    <input type="checkbox" name="sales" id="sales" <?php if($_POST[ 'sales']){ ?>checked="checked"<? }?>> 
    <span class="cbx">Sales</span><br> 
    <input type="checkbox" name="tes" id="tes" <?php if($_POST[ 'tes']){ ?>checked="checked"<? }?>> 
    <span class="cbx">Tes e Infusiones</span> <br> 
    <input type="checkbox" name="otros" id="otros" <?php if($_POST[ 'otros']){ ?>checked="checked" <? }?>> 
    <span class="cbx">Otros</span> <br> 
    <input type="submit" name="tipoProducto" value="Submit" /> 
</form> 

そして、これは、PHPさ:

if(isset($_POST['tipoProducto'])){ 
    // search in all table columns 
    // using concat mysql function 
    if(isset($_POST['especias'])){ 
     $query = "SELECT nombre, usos, peso, foto, `tipo de producto` FROM `producto` WHERE `tipo de producto`='especias'"; 
     $search_result = filterTable($query); 
    } 
    else if(isset($_POST['sales'])){ 
     $query = "SELECT nombre, usos, peso, foto, `tipo de producto` FROM `producto` WHERE `tipo de producto`='sales'"; 
     $search_result = filterTable($query); 
    } 
    else if(isset($_POST['tes'])){ 
     $query = "SELECT nombre, usos, peso, foto, `tipo de producto` FROM `producto` WHERE `tipo de producto`='infusiones'"; 
     $search_result = filterTable($query); 
    } 
    else if(isset($_POST['otros'])){ 
     $query = "SELECT nombre, usos, peso, foto, `tipo de producto` FROM `producto` WHERE `tipo de producto`='infusiones'"; 
     $search_result = filterTable($query); 
    } 
    else if(isset($_POST['especias']) && isset($_POST['sales'])){ 
     $query = "SELECT nombre, usos, peso, foto, `tipo de producto` FROM `producto` WHERE `tipo de producto`='especias'"; 
     $query = "SELECT nombre, usos, peso, foto, `tipo de producto` FROM `producto` WHERE `tipo de producto`='sales'"; 
     $search_result = filterTable($query); 
    } 
}?> 

おかげで、ここでのテストのウェブサイトのリンクです:http://onena.modacanela.com/productos.html

+0

私が思うに、この '' それは完全に有効な構文です@Fil有効なPHP構文 – Fil

+1

ではありませんhttps://3v4l.org/FrJqU – Machavity

+0

Iそれを試してみましたが、 '構文エラー、予期しないファイルの終わりを言っています。 'というエラーが表示されますが、私の答えは – Fil

答えて

0

ここにあなたの元のコードがあります、

<form action="busqueda.php" method="post"> 
    <input type="checkbox" name="especias" id="especias" <?php if($_POST[ 'especias']){ ?>checked="checked"<? } ?>> 
    <span class="cbx">Especias</span><br> 
    <input type="checkbox" name="sales" id="sales" <?php if($_POST[ 'sales']){ ?>checked="checked"<? }?>> 
    <span class="cbx">Sales</span><br> 
    <input type="checkbox" name="tes" id="tes" <?php if($_POST[ 'tes']){ ?>checked="checked"<? }?>> 
    <span class="cbx">Tes e Infusiones</span> <br> 
    <input type="checkbox" name="otros" id="otros" <?php if($_POST[ 'otros']){ ?>checked="checked" <? }?>> 
    <span class="cbx">Otros</span> <br> 
    <input type="submit" name="tipoProducto" value="Submit" /> 
</form> 

あなたの入力に<? } ?>を使用して、if条件の括弧を閉じます。 利用代わり<?php } ?>ここ

コードルックのような、

<form action="busqueda.php" method="post"> 
    <input type="checkbox" name="especias" id="especias" <?php if(true) { ?>checked="checked"<?php } ?>> 
    <span class="cbx">Especias</span><br> 
    <input type="checkbox" name="sales" id="sales" <?php if(true) { ?>checked="checked"<?php }?>> 
    <span class="cbx">Sales</span><br> 
    <input type="checkbox" name="tes" id="tes" <?php if(true){ ?>checked="checked"<?php }?>> 
    <span class="cbx">Tes e Infusiones</span> <br> 
    <input type="checkbox" name="otros" id="otros" <?php if(true){ ?>checked="checked" <?php }?>> 
    <span class="cbx">Otros</span> <br> 
    <input type="submit" name="tipoProducto" value="Submit" /> 
</form> 
+0

こんにちは@Fil、すべてのチェックボックスを最初からチェックして、私は2または3をチェックしたいので、2の結果、1チェックボックスのみの結果だけでなく、ありがとう – Jacofki

関連する問題