我在codeigniter中做了这个功能:
public function get_users_pagination($q, $perpage, $pagenr, $type = 1)
{
$query = $this->db->get_where('korisnici_tbl', array("type" => $type), $perpage,$pagenr);
$this->db->like('email', $q);
$this->db->or_like('name', $q);
return $query->result();
}
但是,当结果小于$ perpage变量时,它仍返回$ perpage数量的行。
因此,如果$ pagenr例如为10并且有2个类型为1的行,它将仅返回其他8个类型2的行。
您可以像这样对OR进行分组
$like = '(email LIKE \'%'.$q.'%\'';
$like .= ' OR name LIKE \'%'.$q.'%\')';
$this->db->where($like);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句