codeigniter active record get query and query without the LIMIT clause

前端 未结 4 1937
梦谈多话
梦谈多话 2020-12-13 21:41

im using active record, its all working ok but i want to set the $data[\"totalres\"] to the total results, i mean, the same query but without the LI

4条回答
  •  时光取名叫无心
    2020-12-13 22:04

    Try this:

    function get_search($start, $numrows, $filter = array()){    
        $tmp= $this->db
        ->select("emp")
        ->from('emp')
        ->join('empr', 'empr.b = empr.id', 'left')
        ->like('code', $code)
        ->_compile_select();
    
        $q= $this->db->limit($numrows, $start)->get();
    
        // number of rows WITHOUT the LIMIT X,Y filter
    
        $data["totalres"] = $this->db->query($tmp)->num_rows();
    
        if ($q->num_rows() > 0){        
            $data["results"] = $q->result();
        } else {
            $data["results"] = array();
        }   
        return $data;
    }    
    

提交回复
热议问题