php - How to search data based on having value in comma in codeigniter? -
i can search data based on if value of row single not separated comma. 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 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 used transfer value of job posted date,location,and skills on url
and routes code:
$route['job']="job/alljobs"; $route['job/(:any)']="job/searchjobs/$1";
and model code
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() $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() $row) { $return_array[] = $row; } return $return_array; } return array(); } }
now have problem if user wants search job skills php, android, ios how manage this?
Comments
Post a Comment