php - Use multiple checkboxes to return MySQL results -


i trying create search function allows user choose multiple categories, select submit, , php return mysql results match selected categories.

i without ajax or jquery, use if required. newer world of php, think i'm on right track, love assistance of getting correct.

html

<form action="filter.php" method="post">      <p class="searching">filter category</p>      <section class="box"><input type="checkbox" name="fill" class="check" value="arts/culture"/><img class="lilicon" src="img/anc.png"><h5>arts/culture</h5></section>      <section class="box"><input type="checkbox" name="fill" class="check" value="seniors"/><img class="lilicon" src="img/senior.png"><h5>seniors</h5></section>      <section class="box"><input type="checkbox" name="fill" class="check" value="youth"/><img class="lilicon" src="img/youth.png"><h5>youth</h5></section>      <section class="box"><input type="checkbox" name="fill" class="check" value="animals"/><img class="lilicon" src="img/pet.png"><h5>animals</h5></section>      <section class="box"><input type="checkbox" name="fill" class="check" value="community"/><img class="lilicon" src="img/comm.png"><h5>community</h5></section>       <section class="box"><input type="checkbox" name="fill" class="check" value="crisis support"/><img class="lilicon" src="img/cs.png"><h5>crisis support</h5></section>      <section class="box"><input type="checkbox" name="fill" class="check" value="environment"/><img class="lilicon" src="img/leaf.png"><h5>environment</h5></section>      <section class="box"><input type="checkbox" name="fill" class="check" value="faith based"/><img class="lilicon" src="img/pray.png"><h5>faith based</h5></section>       <section class="box"><input type="checkbox" name="fill" class="check" value="people disabilities"/><img class="lilicon" src="img/chair.png"><h5>people disabilities</h5></section>      <input type="submit" name="submit" id="filter" value="filter"/>      </form> 

php

<?php $variable=$_post['fill']; $i = 0; foreach ($variable $variablename) {     $i++;     $variablename[number]; }  $result = "select * opportunity `category`=$variablename"; $num_rows = mysql_num_rows($result);    echo "<div class='holder'>";      if(mysql_num_rows($result) > 0)    {        while($results = mysql_fetch_array($result));    }   

i changed value of submit 1

<input type="submit" name="submit" id="filter" value="1"/>     if (intval($_post['submit') == 1){   $count = 0;   $sql = "select * opportunity `category` in ( ";   $chk = $_post['chk'];   foreach($chk $value){     $sql .= "'$value',"     $count++;   }   if ($count > 0){     $sql = substr($sql,0,-1) . ');';  // remove trailing comma , close       // sql , output go here    } } 

if youth , animals selected $sql be:

select * opportunity `category` in ('youth','animals'); 

html

<form action="filter.php" method="post"> <p class="searching">filter category</p> <section class="box"><input id="chk1" type="checkbox" name="chk[]" class="check" value="arts/culture"/><img class="lilicon" src="img/anc.png"><h5>arts/culture</h5></section> <section class="box"><input id="chk2" type="checkbox" name="chk[]" class="check" value="seniors"/><img class="lilicon" src="img/senior.png"><h5>seniors</h5></section> <section class="box"><input id="chk3" type="checkbox" name="chk[]" class="check" value="youth"/><img class="lilicon" src="img/youth.png"><h5>youth</h5></section> <section class="box"><input id="chk4" type="checkbox" name="chk[]" class="check" value="animals"/><img class="lilicon" src="img/pet.png"><h5>animals</h5></section> <section class="box"><input id="chk5" type="checkbox" name="chk[]" class="check" value="community"/><img class="lilicon" src="img/comm.png"><h5>community</h5></section>  <section class="box"><input id="chk6" type="checkbox" name="chk[]" class="check" value="crisis support"/><img class="lilicon" src="img/cs.png"><h5>crisis support</h5></section> <section class="box"><input id="chk7" type="checkbox" name="chk[]" class="check" value="environment"/><img class="lilicon" src="img/leaf.png"><h5>environment</h5></section> <section class="box"><input id="chk8" type="checkbox" name="chk[]" class="check" value="faith based"/><img class="lilicon" src="img/pray.png"><h5>faith based</h5></section>  <section class="box"><input id="chk9" type="checkbox" name="chk[]" class="check" value="people disabilities"/><img class="lilicon" src="img/chair.png"><h5>people disabilities</h5></section> <input type="submit" name="submit" id="filter" value="1"/>     </form>  

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -