Welcome Guest, Not a member yet? Register   Sign In
Activerecord - getting totalnumber of query when limit is used
#7

[eluser]barbazul[/eluser]
[quote author="WolfgangA" date="1186598375"]Thanks for the link to the pagination class.
However this does not adress the issue i have.
My problem is: I need to get the total number of rows that match a (complex)query as well as only the resultset when using the 'limit' option.
The only way i see so far is to do 2 queries, which i would like to avoid.

Wolfgang[/quote]

running two queries IS the way to go

Code:
$this->db->select("COUNT(id) AS total_num")
$this->db->from("table");
$this->db->where($conditions);
$first = $this->db->get();
$limit = $first->total_num;

$this->db->select("fields")
$this->db->from("table");
$this->db->where($conditions);
$this->db->limit($limit);
$second = $this->db->get();
Or something like that


Messages In This Thread
Activerecord - getting totalnumber of query when limit is used - by El Forum - 09-13-2007, 09:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB