Hi guys,
I'm building search engine which has many fields:
<input type="checkbox" name="who1" value="1" />Michael
<input type="checkbox" name="who2" value="1" />John
<input type="checkbox" name="who3" value="1" />Andrew
<input type="checkbox" name="who4" value="1" />Sean
<input type="checkbox" name="who5" value="1" />Alex
<input type="checkbox" name="who6" value="1" />Martin
<select name="sex">
<option>Male</option>
<option>Female</option>
</select>
<input type="text" name="age_min" class="text" />
<input type="text" name="age_max" class="text" />
etc...........
Now I'would like to display search results, and I'm bit stuck. What is the best way to write the syntax for mysql using some kind of loop+array, I was trying to go step by step like:
if(isset($_POST['who1'])) {
$search = "person='Michael"; }
if(isset($_POST['who2'])) {
$search = "person='John'"; }
..................
if($_POST['sex']=="Male") {
$search = " AND sex='Male"; }
if($_POST['sex']=="Female") {
$search = " AND sex='Female"; }
$query2 = mysql_query("SELECT * FROM profil WHERE $szukaj");
But that only allows me to have one search string per section plus it's a long code. I know I can use
$search .= " OR person='John'"
But that won't work if person1 isn't selected. How can I use loop + maybe array to shorten the code and make it work properly ... ?
Thanks for any advices