Welcome Guest, Not a member yet? Register   Sign In
Active Record: count_all_results() problem
#1

[eluser]Unknown[/eluser]
I'm trying to get pagination working. I'm querying my products table with a join and a where clause. I am sticking to active record style - but need to get the total results of my query - so I can pass it to the $config['total_rows'] of the pagination class.

so in my model:

Code:
$this->db->select('products.name, products.image, products.slug, products.price');
        $this->db->from('products');
        $this->db->join('categories', 'products.cat_id = categories.id');
        $this->db->where('categories.slug', $slug);
        $this->productsCount = $this->db->count_all_results() //this is where it's crapping out
        $this->db->limit($limit, $start);        
        $query = $this->db->get();        
        
       return $query->result_array();


I get a database error:


Quote:Error Number: 1096
No tables used
SELECT * LIMIT 9, 3
Filename: C:\xampp\htdocs\restaurant\system\database\DB_driver.php
Line Number: 330

if I simply echo the $this->db->count_all_results() and exit - I get the correct # of rows. If I move it below the limit clause - I get incorrect number of rows.

So what am I doing wrong? I want to stick to active record as much as possible.

thanks in advance...





Messages In This Thread
Active Record: count_all_results() problem - by El Forum - 02-04-2013, 09:53 PM
Active Record: count_all_results() problem - by El Forum - 02-05-2013, 03:29 AM
Active Record: count_all_results() problem - by El Forum - 02-05-2013, 03:03 PM
Active Record: count_all_results() problem - by El Forum - 04-15-2013, 07:41 AM
Active Record: count_all_results() problem - by El Forum - 04-15-2013, 08:18 AM
Active Record: count_all_results() problem - by El Forum - 04-15-2013, 08:38 AM
Active Record: count_all_results() problem - by El Forum - 04-15-2013, 09:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB