dongyi3616
2017-10-12 20:00
浏览 55
已采纳

使用Code Igniter在数据库中搜索精确单词

I am filtering some data, I have a field called "faculty" and the options are "Professor, Associate Professor, Research Professor" ... so on. My filtering works for every other field but for this specific case I am having trouble because the professor word appears in all the data and as a result, I get all the data that matches the word "professor" so it is not filtering anything. How can I make it to search only for the specific word 'Professor' and avoid getting all the others (research professor, associate professor...)?

// My code

function get_search_filters($limit, $start, $search_faculty) 
{
    $this->db->order_by('lname', 'asc'); //order records by last name
    $this->db->limit($limit, $start);

    /* search keyword in all columns*/
    $this->db->like('faculty', $search_faculty);

    $query = $this->db->get('expertise');
    if ($query->num_rows() > 0) {
        foreach ($query->result() as $row) {
            $data[] = $row;
        }
        return $data;
    }
    return false;
}
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douba9020 2017-10-12 20:06
    已采纳
    $this->db->order_by('lname', 'asc'); //order records by last name
    $this->db->limit($limit, $start);
    
    $this->db->where('faculty', $search_faculty);
    $query = $this->db->get('expertise');
    

    https://www.codeigniter.com/userguide3/database/query_builder.html#looking-for-specific-data

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题