Hello guys, Please, I need help concerning a multiple criteria search form using php. Can somebody help me out here.I have attached the file and the sql here. The format for the search is that you can use any of the search parameters or combine more than one for your search.

Trust You guys will help

    not inclined toward downloading mystery zip files (for obvious reasons) why not post it in the forum.

      ok here is the page and my sql

      The Search Page

      [code=html]

      <form "search" method="get" action="<?php echo $_SERVER['PHP_SELF']?>">
      <table align="center" border="1" cellpadding="5" cellspacing="0" width="750">
      <tr>
      <th colspan="2" scope="col">SEARCH CV</th>
      </tr>
      <td width="236">Vacancy Code</td>
      <td width="488"><input type="Text" name="vacancycode" id="vacancycode"style="width: 180px;" value=""></td>
      </tr>
      <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      </tr>
      <tr>
      <td width="236">Keyword(s)</td>
      <td width="488"><input type="Text" name="keyword" id="keyword"style="width: 180px;" value=""></td>
      </tr>
      <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      </tr>
      <tr>
      <td>Experience</td>
      <td>From:<input type="Text" name="exp1" id="exp1"style="width: 25px;" value=""> To: <input type="Text" name="exp2" id="exp2"style="width: 25px;" value=""> in years</td>
      </tr>
      <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      </tr>
      <tr>
      <td>Industry</td>
      <td><select name="industry" id="industry" style="width: 170px;">
      <option value="">Please select</option>
      <option value="accounting">ACCOUNTING</option>
      <option value="water_development">WATER DEVELOPMENT</option>
      <option value="wildlife">WILD LIFE</option>
      </select></td>
      </tr>
      <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      </tr>
      <tr>
      <td>Education Level</td>
      <td><select name="edulevel" id="edulevel" style="width: 160px;">
      <option value="0">--Select--</option>
      <option>MBA/PGD</option>
      <option>Bachelor</option>
      <option>HND</option>
      <option>OND</option>
      <option>Others</option>
      </select></td>
      </tr>
      <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      </tr>
      <tr>
      <td>Language</td>
      <td><select name="language" id="language" style="width: 110px;">
      <option value="">Please select</option>
      <option >English</option>
      <option> French</option>
      <option>Arabic</option>
      </select></td>
      </tr>
      <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      </tr>
      <tr>

      <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      </tr>
      <tr>
      <td>Nationality / Country of Origin</td>
      <td><select name="nationality" id="nationality" style="width: 221px;">
      <option value="">Please select</option>

                      <option >Ukraine</option>
                      <option >United Arab Emirates</option>
                      <option >United Kingdom</option>
                      <option >Vatican City</option>
                      <option >Vietnam</option>
                      <option>Zambia</option>
                      <option >Zimbabwe</option>
                      <option >[Other country]</option></select></td>

      </tr>
      <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      </tr>
      <tr>
      <td colspan="2" align="center"><input type="Submit" value="Search" class="button" ></td>
      </tr>

      </table>

      </form>

      [/code]

      MY SQL

      -- phpMyAdmin SQL Dump
      -- version 3.3.9
      -- [url]http://www.phpmyadmin.net[/url]
      --
      -- Host: localhost
      -- Generation Time: Apr 20, 2012 at 07:15 AM
      -- Server version: 5.5.8
      -- PHP Version: 5.3.5
      
      SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
      
      
      /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
      /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
      /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
      /*!40101 SET NAMES utf8 */;
      
      --
      -- Database: `newstresert`
      --
      
      -- --------------------------------------------------------
      
      --
      -- Table structure for table `application`
      --
      
      CREATE TABLE IF NOT EXISTS `application` (
        `id` int(10) NOT NULL AUTO_INCREMENT,
        `vacancycode` varchar(10) NOT NULL,
        `title` varchar(7) NOT NULL,
        `fname` varchar(50) NOT NULL,
        `lname` varchar(50) NOT NULL,
        `address` varchar(200) NOT NULL,
        `city` varchar(100) NOT NULL,
        `state` varchar(100) NOT NULL,
        `phone` varchar(50) NOT NULL,
        `email` varchar(100) NOT NULL,
        `dob` varchar(20) NOT NULL,
        `sex` varchar(10) NOT NULL,
        `nationality` varchar(30) NOT NULL,
        `nysc` varchar(20) NOT NULL,
        `instituname1` varchar(100) NOT NULL,
        `instituaddrs1` varchar(30) NOT NULL,
        `course1` varchar(30) NOT NULL,
        `qualification1` varchar(15) NOT NULL,
        `eduqualiothers` varchar(15) NOT NULL,
        `startyr1` varchar(6) NOT NULL,
        `endyr1` varchar(6) NOT NULL,
        `instituname2` varchar(100) NOT NULL,
        `instituaddrs2` varchar(30) NOT NULL,
        `course2` varchar(30) NOT NULL,
        `qualification2` varchar(15) NOT NULL,
        `startyr2` varchar(6) NOT NULL,
        `endyr2` varchar(6) NOT NULL,
        `instituname3` varchar(100) NOT NULL,
        `instituaddrs3` varchar(30) NOT NULL,
        `course3` varchar(30) NOT NULL,
        `qualification3` varchar(15) NOT NULL,
        `startyr3` varchar(6) NOT NULL,
        `endyr3` varchar(6) NOT NULL,
        `pqualifi1` varchar(15) NOT NULL,
        `pqualifiaward1` varchar(20) NOT NULL,
        `countryawrd1` varchar(15) NOT NULL,
        `pqualifistartyr1` int(5) NOT NULL,
        `pqualifi2` varchar(15) NOT NULL,
        `pqualifiaward2` varchar(15) NOT NULL,
        `countryawrd2` varchar(15) NOT NULL,
        `pqualifistartyr2` int(5) NOT NULL,
        `pqualifi3` varchar(15) NOT NULL,
        `pqualifiaward3` varchar(15) NOT NULL,
        `countryawrd3` varchar(15) NOT NULL,
        `pqualifistartyr3` int(5) NOT NULL,
        `experience` int(5) NOT NULL,
        `companyname` varchar(35) NOT NULL,
        `sector` varchar(50) NOT NULL,
        `countryemp1` varchar(30) NOT NULL,
        `employstartdate` varchar(18) NOT NULL,
        `employenddate` varchar(18) NOT NULL,
        `jobtitle` varchar(20) NOT NULL,
        `duties` varchar(150) NOT NULL,
        `companyname2` varchar(35) NOT NULL,
        `sector2` varchar(50) NOT NULL,
        `countryemp2` varchar(30) NOT NULL,
        `employstartdate2` varchar(18) NOT NULL,
        `employenddate2` varchar(18) NOT NULL,
        `jobtitle2` varchar(20) NOT NULL,
        `duties2` varchar(150) NOT NULL,
        `companyname3` varchar(35) NOT NULL,
        `sector3` varchar(50) NOT NULL,
        `countryemp3` varchar(30) NOT NULL,
        `employstartdate3` varchar(18) NOT NULL,
        `employenddate3` int(18) NOT NULL,
        `jobtitle3` int(20) NOT NULL,
        `duties3` int(150) NOT NULL,
        `cv` varchar(50) NOT NULL,
        PRIMARY KEY (`id`)
      ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
      

      What I need is to be able to search the database with any of the criteria or combine more than one of the criterias

        so have you tried to write anything for yourself; or are you just expecting us to write it for you?

          Yes I have been able to do something but what I was able to do was just for single search it could not do more than a single search.

            ok your problem is relatively simple for you to solve, but i will point you in the right direction, you need to look up MYSQL LIKE statements, have a look at this page, this is just a small example of what you need. But i also would look at this http://www.w3schools.com/ajax/ajax_aspphp.asp for a really cool feature of getting result instantly.

            and then you can expand in to regular expressions to make your search a little bit more clever.

              Thank you greatly,

              I have checked the page and it is nice but I notice that you can just do a single search criteria at once which I have been able to do sometimes ago.

              What am looking at is a situation where you can search at once with multiple criteria
              for instance you are looking for a male who has 3 years and above in experience who lives in a particular country and has a particular speciality, if there is none it should return a default message for blank report.

                Hi either way you will have to use the LIKE statment with or statements, or create a function which dynamically update your search query depending on which option has been chosen, or you can write our your search query for each individual selection with elseif statements. I would prefer the dynamic stamtent query depending on what the user has chosen.

                There are a few approaches you can use...

                Why not show us your first attempt or approach you are using so we can see where we can help 🙂

                  Here is what I have written so far but it is returning parse error and also I am yet to work on the experience section

                  <?php
                  include "stresert/include/config.php";
                   ?>
                   <?php
                   $vacancycode=$_POST["vacancycode"];
                   $sector=$_POST["sector"];
                   $edulevel=$_POST["edulevel"];
                   $nationality=$_POST["nationality"];
                   $o=$_POST["o"];
                  
                          $rest="";
                  			 $text="Search Keywords : ";
                  
                  			  if($vacancycode!="")
                  				 {
                  				 	if($rest=="")
                  						{
                  							$rest.=" inner join $vacancycode on application.id=$vacanycode.id and title='$vacancycode'";
                  							$text.="vacancycode = $vacancycode";
                  						}
                  						else
                  						{
                  						$rest.=" $o  inner join $vacancycode on application.id=$vacanycode.id and title='$vacancycode'";
                  						$text.=", vacancycode = $vacancycode";
                  						}
                  				 }
                  				 /*
                  				 if($name!="")
                  				 {
                  				 	if($rest=="")
                  						{
                  					 $rest.=" where fname like '$name%' or mname like '$name%' or lname like '$name%' ";
                  					 $text.="Name like $name ";
                  					 }
                  					 else {
                  					 	$rest.="$o where fname like '$name%' or mname like '$name%' or lname like '$name%' ";
                  						 $text.="Name like $name ";
                  					 }
                  				 }*/
                  				 if($sector!="")
                  				 {
                  				 	if($rest=="")
                  						{
                  							$rest.=" where sector='$sector' ";
                  							$text.="Sector = $sector";
                  						}
                  						else
                  						{
                  						$rest.=" $o sector='$sector' ";
                  						$text.=", Sector = $sector";
                  						}
                  				 }
                  				 if($edulevel!="")
                  				 {
                  				 	if($rest=="")
                  						{
                  							$rest.="where edulevel='$edulevel' ";
                  							$text.="Education Level = $edulevel";
                  						}
                  						else
                  						{
                  						$rest.=" $o edulevel='$edulevel' ";
                  						$text.=", Education Level = $edulevel";
                  						}
                  				 }
                  
                  				  if($nationality!="")
                  				 {
                  				 	if($rest=="")
                  						{
                  							$rest.="where nationality = '$nationality' ";
                  							$text.="Nationality = $nationality ";
                  						}
                  						else
                  						{
                  						$rest.=" $o  nationality = '$nationality' ";
                  						$text.=", Nationality = $nationality ";
                  						}
                  				 }
                  				/* 
                  				 if($wdate!="")
                  				 {
                  				 	if($rest=="")
                  						{
                  							$rest.="where wedding = '$wdate' ";
                  							$text.="Wedding Date = $wdate";
                  						}
                  						else
                  						{
                  						$rest.=" $o  wedding = '$wdate' ";
                  						$text.=", Wedding Date = $wdate";
                  						}
                  				 }
                  				 if($city!="")
                  				 {
                  				 	if($rest=="")
                  						{
                  							$rest.="where tcity = '$city' ";
                  							$text.="City = $city";
                  						}
                  						else
                  						{
                  						$rest.=" $o  tcity = '$city' ";
                  						$text.=", City = $city";
                  						}
                  				 }
                  
                  
                  
                  				  if($email!="")
                  				 {
                  				 	if($rest=="")
                  						{
                  							$rest.="where email like '$email%'";
                  							$text.="Email = $email";
                  						}
                  						else
                  						{
                  						$rest.=" $o email like '$email%' ";
                  						$text.=", Email = $email";
                  						}
                  				 }
                  
                  				 */
                  				if($rest!="")
                  				{
                  				$rest=$rest;
                  				}
                  				else
                  				{
                  					//die("Enter Search Parameter<br><br><br><br><br><br><br><br><br><br><br>");
                  				}
                  
                  $sql="select application.* from application $rest order by vacancycode"; 
                  $result=mysql_query($sql,$connection) or die(mysql_error());			
                  $num=mysql_num_rows($result);
                  ?>
                  
                   <table border="1" align="center" width="500">
                  
                    <tr align="left" valign="top">
                      <th scope="col">Vacancy Code</th>
                      <th scope="col">Applicant Name</th>
                      <th scope="col">Education Level</th>
                      <th scope="col">Experience</th>
                      <th scope="col">Industry</th>
                      <th scope="col">Nationality</th>
                      <th scope="col">Cv</th>
                      <th scope="col">Download</th>
                      <th scope="col">Delete</th>
                       </tr>
                       <?php
                  	 //$counter=0;
                  while($row=mysql_fetch_array($result))
                  {
                  ?>	
                  <td><?php echo $row['vancanycode'] ?></td>
                   <td><?php echo $row['title']." ".$row['fname']." ".$row['lname'] ?></td>
                    <td><?php echo $row['edulevel'] ?></td>
                   <td><?php echo $row['experience'] ?></td>
                   <td><?php echo $row['sector'] ?></td>
                   <td><?php echo $row['nationality'] ?></td>
                    <td><?php echo $row['cv'] ?></td>
                   <td><a href='cv/<?php echo $row['cv'] ?>'>Download</a></td>
                   <td><a href='deleteallphp?id=<?php echo $row['vcode'] ?>'>Delete</a></td>
                   </tr>	
                   </td>
                   <?php
                   }
                  ?>
                  
                  </table>
                    4 years later

                    How can i fullfill all the search criterias required for ecommerce websites like peppertap.com

                      Write a Reply...