[eluser]helmutbjorg[/eluser]
Hi Guys,
I'm using ignitedrecord but this problem is the same in active record.
Say i have the following
Code:
$this->user->select('name');
$this->user->where('state', 'something');
$this->user->join('postcodes', 'postcodes.code = users.postcode');
$this->user->find_all();
Now that is a rather simple query. Let's say I want to use the pagination class I am required to do this...
Code:
// Get total count for pagination
$this->user->select('name');
$this->user->where('state', 'something');
$this->user->join('postcodes', 'postcodes.code = users.postcode');
$config['total_rows'] = $this->user->count();
$this->pagination->initialize($config); // Theres more here but you get the gist
// Now do the query again to get the actual rows
$this->user->select('name');
$this->user->where('state', 'something');
$this->user->join('postcodes', 'postcodes.code = users.postcode');
// With the limit in place
$this->user->limit(?);
$this->user->offset(?);
$this->user->find_all();
Notice how I needed to write the main parts of the query twice. Some of my querys are reasonably lengthy and it is kind of annoying have to repeat the same code simply to get the count and then do it all again to just add the offset and limit. Is there a better way?