views:

34

answers:

1

I am working in PHP(with Symfony Framework) and i want to create a search based on multiple values selected from multiple selection element, i.e there will be multiple selection dropdown elements for like countries, cities, age etc.. and the values from them will query a data table and give the desired search output. (all values are not mandatory, will work with atleast one value). the idea will also do..

A: 

I am using Symfony as framework, so my code goes like this,

In Action,

$values=$this->form->getValues();
$nation=$values['nation'];
$township=$values['township'];
$job=$values['job'];
$programming_language_known=$values['programming_language_known'];
if($nation != null || $township != null || $job != null || $programming_language_known != null){
//calling the function 
$this->search_data=Jobs::jobSearch(...parameter's here...);  
}else{ // search_data = null }

in Model

public static function jobSearch($nation=null, $township=null, $job=null, $programming_language=null)
{
   $c=new Criteria();
   if($nation != null)
   {
      $c->addAnd(JobsPeer::NATION,$nation);
   } 
   if($township != null)
   {
      $c->addAnd(JobsPeer::TOWNSHIP,$township);
   }
   if($job != null)
   {
      $c->addAnd(JobsPeer::JOB,$job);
   }  
   if($programming_language != null)
   {
      $c->addAnd(JobsPeer::LANGUAGE,$programming_language);
   }
   $jobs=JobsPeer::doSelect($c);
   return $jobs;
}

It works for now but i dont know its a good logic or not....

Harish Kurup