doulu4233 2014-11-19 13:52
浏览 20

如何根据codeigniter中的逗号值来搜索数据?

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大