[eluser]WolfgangA[/eluser]
Hello,
using the activerecord class, i try to get the total number of records of a query and then only the records defined by limit.
So i need something like: "Record 20 - 40 of 1250" where i only fetch record 20-40.
Because the query joins more tables, i cannot use a simple count over one table.
I tried this:
Code:
$this->db->select('buchung.*, fz_klasse.klasse, fz_typ.typ, concat(vorname, " ", nachname) as mitarbeiter');
$this->db->from('buchung');
$this->db->join('fahrzeug', 'buchung.id_fz = fahrzeug.id', 'left');
$this->db->join('fz_klasse', 'fz_klasse.id = fahrzeug.id_klasse', 'left');
$this->db->join('fz_typ', 'fz_typ.id = fahrzeug.id_typ', 'left');
$this->db->join('mitarbeiter', 'mitarbeiter.id = buchung.id_mitarbeiter', 'left');
$this->db->where('buchung.id_fz', $id_fz);
if ($like != '') { $this->db->like($like); }
// get total number of records
$query = $this->db->get();
$ret['totalcount'] = $query->num_rows();
// qurery again, but limit the resultset
if ($limit > 0) { $this->db->limit($limit, $start); }
if ($orderby != '') { $this->db->orderby($orderby); }
$query = $this->db->get();
$ret['data'] = $query->result();
The problem is that after the first
Code:
$query = $this->db->get();
the query itself seems to be reset. So adding the limit and orderby clause fails.
The only way i have found would be to duplicate the entire query, but i would like to avoid that.
So is there any "nice" workaround possible?
Thanks in advance
Wolfgang