Creating the searching in php

hey guys, im new to all this php stuff.
I have a project in this semester to create an HR contract system for the university, here are my requirements:

  1. Add Contracts
  2. Delete Contracts
  3. Edit Contracts
  4. View Contracts
  5. Search Contracts

i have done all the 4 options but now im stuck in the 5th option. i have to use checkboxes filters for search and first and the last name fields.

here is my form code

<form method="post" action="searchCode.php">
First Name: 
<input name="name" type="text" id="name" />
Middle Name: 
<input name="mname" id="mname" type="text" />
Last Name: 
<input name="lname" id="lname" type="text" />
<input type="text" name="date" id="currentdate" />

<input type="checkbox" name="gender[]" value="male" />Male<br />
<input type="checkbox" name="gender[]" value="female" />Female

<input name="desig[]" type="checkbox" value="lecturar"/>Lecturar 
<input type="checkbox" name="desig[]" value="professor" />Professor 
<input type="checkbox" name="desig[]" value="assistantProfessor" />Assistant Professor
<input type="checkbox" name="desig[]" value="associateProfessor" />Associate Professor
<input type="checkbox" name="desig[]" value="researchAssociate" />Research Associate<br />
<input type="checkbox" name="desig[]" value="advisor" />Advisor
<input type="checkbox" name="desig[]" value="HOD" </span>






<input name="dept[]" type="checkbox" value="Comuter Science"  />Computer Science
<input type="checkbox" name="dept[]" value="Health Informatics Unit" />Health Informatics Unit
<input name="dept[]" type="checkbox" value="Electrical Engineering" />Electrical Engineering
<input type="checkbox" name="dept[]" value="Management Sciences" />Management Sciences<br />
<input type="checkbox" name="dept[]" value="Mathamatics" />Mathamatics
<input type="checkbox" name="dept[]" value="Physics" />Physics
<input type="checkbox" name="dept[]" value="Bio Sciences" />Bio Sciences
<input type="checkbox" name="dept[]" value="Meteorology" />Meteorology
<input type="checkbox" name="dept[]" value="Architecture" />Architecture

<input name="scales[]" type="checkbox" value="sg1"  />SG-I
<input name="scales[]" type="checkbox" value="sg2"  />SG-II
<input name="scales[]" type="checkbox" value="sg3"  />SG-III
<input name="scales[]" type="checkbox" value="sg4"  />SG-IV
<input name="scales[]" type="checkbox" value="ras" />RA 
<input name="scales[]" type="checkbox" value="og1nphd" />OG-I-
<input name="scales[]" type="checkbox" value="og2nphd" />OG-II-NonPhd
<input name="scales[]" type="checkbox" value="og3nphd" />OG-III-NonPhd
<input name="scales[]" type="checkbox" value="og4nphd" />OG-IV-NonPhd
<input name="scales[]" type="checkbox" value="og2phd" />OG-II-Phd
<input name="scales[]" type="checkbox" value="og3phd" />OG-III-Phd
<input name="scales[]" type="checkbox" value="og4phd" />OG-IV-Phd</p>

now i cant seem to get it in my mind tht how the hell im going to do tht…shud i use ifs and elses, in tht case it can get upto 256 combinations.

and 1 more thing all these things are in one table…please gyus help me

You can build the query form the POST array. I don’t know what your table looks like but here is a theoretical example.


foreach($_POST as $k=>$v){ //cycle through post array

$k=mysql_escape_string($k);//clean data
$v=mysql_escape_string($v);//clean data


case 'first_name':
$where.=' AND first_name like "%'.$v.'%"  '

case 'last_name':
$where.=' AND last_name like "%'.$v.'%"  '


$sql="SELECT * FROM table WHERE 1".$where; //assemble query