I can search data based on if the value of the row is single that is not separated by comma. As the view code as
<form id="search" class="form-horizontal" action="" method="post">
<td colspan="2">
<div class="form-group">
<input name="job_posted_date" id="job_posted_date" class="form-control" type="text" placeholder="posted date" value="<?php echo set_value('job_posted_date'); ?>">
</div>
</td>
<td colspan="1">
<div class="form-group">
<input name="job_skills" id="job_skills" class="form-control" type="text" placeholder="skills" value="<?php echo set_value('job_skills'); ?>">
</div>
</td>
<td colspan="2">
<div class="form-group">
<input name="job_location" id="job_location" class="form-control" type="text" placeholder="location" value="<?php echo set_value('job_location'); ?>">
</div>
</td>
<td colspan="5">
<div class="form-group">
<button type="submit" class="btn btn-red btn-sm">
Filter records
</button>
And the script code as:
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script>
$("#search").submit(function(){
var search="";
var searchName = $('#job_posted_date').val();
var searchsite_location = $('#job_skills').val();
var searchDesignation = $('#job_location').val();
if(searchName!="")
{
search+="postdate:"+searchName;
}
if(searchsite_location!="")
{
if(search!="")
search+="+jobskill:"+searchsite_location;
else
search+="jobskill:"+searchsite_location;
}
if(searchDesignation!="")
{
if(search!="")
search+="+joblocation:"+searchDesignation;
else
search+="joblocation:"+searchDesignation;
}
window.location.href = '<?php echo base_url('job')?>/'+search;
return false;
});
</script>
This above script code is used as transfer the value of job posted date,location,and skills on the URL
and the routes code:
$route['job']="job/alljobs";
$route['job/(:any)']="job/searchjobs/$1";
and the model code as
public function searchJob($search)
{
if($search!='key')
{
$postdate=$jobskill=$joblocation='';
$searchdata=explode("+",$search);
for($i=0;$i<sizeof($searchdata);$i++)
{
$searchfield=explode(":",$searchdata[$i]);
if($searchfield[0]=='postdate')
{
$postdate=$searchfield[1];
}
else if($searchfield[0]=='jobskill')
{
$jobskill=$searchfield[1];
}
else if($searchfield[0]=='joblocation')
{
$joblocation=$searchfield[1];
}
}
$this->db->select('*');
!empty($postdate)?($this->db->like('job_posted_on',$postdate,'both')):"";
!empty($jobskill)?($this->db->like('job_skills',$jobskill,'both')):"";
!empty($joblocation)?($this->db->like('job_location', $joblocation)):"";
$result = $this->db->get('job');
if($result -> num_rows() > 0)
{
foreach($result->result_array() as $row)
{
$return_array[] = $row;
}
return $return_array;
}
return array();
}
else
{
$this->db->select('*');
$result = $this->db->get('jobs');
if($result -> num_rows() > 0)
{
foreach($result->result_array() as $row)
{
$return_array[] = $row;
}
return $return_array;
}
return array();
}
}
Now I have the problem is that if user wants to search job skills like php, android, ios than how to manage this?