在哪里可以在此代码上添加like语句?我想允许用户搜索与所输入文本相似的任何文档,就像'%$ search%;
public function getDoc($param=''){
if($this->User->PrincipalType!="All")$where['tbl_document.PrincipalType']=$this->User->PrincipalType;
if(!isset($param['RecordID']) || $param['RecordID']==''){
$where['tbl_document.Status !=']='Removed';
$this->db->select('tbl_document.*,cr.FirstName,cr.MiddleName,cr.LastName,up.FirstName as UFName,up.MiddleName as UMName,up.LastName as ULName');
$this->db->from('tbl_document');
$this->db->join('tbl_user `cr`', 'tbl_document.CreatedBy = cr.ID','left');
$this->db->join('tbl_user `up`', 'tbl_document.UpdatedBy = up.ID','left');
if(isset($param['DocTrack']) && $param['DocTrack']!='') $where['tbl_document.ID']=$param['DocTrack'];
$this->db->where($where);
if(isset($param['DocTrack']) && $param['DocTrack']!='')$this->db->or_where('tbl_document.Title',$param['DocTrack']);
$this->db->order_by('DateCreated', 'desc');
$query = $this->db->get();
$return=$query->result();
}
答案 0 :(得分:1)
假设您要搜索$param['DocTrack']
,则可以使用以下两种方法执行类似的查询,如下所示:
1. $this->db->like('tbl_document.Title','%'.$param['DocTrack'].'%')
2. $this->db->where("tbl_document.Title LIKE '%".$param['DocTrack']."%'");
希望它对您有帮助:)