mysql - Multiple checkbox search query fetching data from database in php -
i have multiple checkbox search query fetches data database. below code:
html code:
<form action="search.php" method="post"> <input type="checkbox" name="cloth_color[]" value="red" /> red <br> <input type="checkbox" name="cloth_color[]" value="yellow" /> yellow <br> <input type="checkbox" name="cloth_color[]" value="blue" /> blue <br> <input type="checkbox" name="cloth_color[]" value="green" /> green <br> <input type="checkbox" name="cloth_color[]" value="magenta" /> magenta <br> <input type="checkbox" name="cloth_color[]" value="black" /> black <br> <input type="checkbox" name="cloth_color[]" value="white" /> white <br> <input type="submit" value="search"> </form> php code:
<?php $checkbox1 = $_post['cloth_color']; $chk=""; foreach($checkbox1 $chk1) { $chk .= $chk1; } if($_post['cloth_color'] != "") { $query = "select * clothings colorofcloth = '$chk'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { $colorofcloth = $row['colorofcloth']; echo 'the cloth ' . $colorofcloth . ' color'; echo '<br>'; } } ?> now if choose 1 option search select box query. if select 2 or more color dont query. appreciated.
p.s. have multiple joins in mysql query place stuck presenting clear question possible here. intent convert mysql mysqli before launch of code. thank :)
<?php $checkbox1 = $_post['cloth_color']; $chk=""; foreach($checkbox1 $chk1) { $chk .= $chk1 . ","; } if($_post['cloth_color'] != "") { $query = "select * clothings colorofcloth in($chk)"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { $colorofcloth = $row['colorofcloth']; echo 'the cloth ' . $colorofcloth . ' color'; echo '<br>'; } ?> you can try code use in() of mysql can pass multiple , separated values.
hope helps
Comments
Post a Comment