php - codeigniter: pagination + table libraries (not working) -


i need on code igniter app..i can't seem find out what's causing pagination not work

here's controller

$limit = 15;         $uri_segment = 4;         $this->load->helper('string');          $offset = $this->uri->segment( $uri_segment );         log_message('error',date('y-m-d h:i:s', time()));         //load         //$products = $this->products_model->get_all();         $products = $this->products_model->get_products($limit, $uri_segment);         //var_dump($products);          log_message('error', $products );          //pagination         $this->load->library('pagination');         $config['base_url'] = site_url('admin/products/index/');         $config['total_rows'] = $this->products_model->count_all();         $config['per_page'] = $limit;         $config['uri_segment'] = $uri_segment;         $this->pagination->initialize($config);          $data['pagination'] = $this->pagination->create_links();          //table         $this->load->library('table');         $this->table->set_empty(" ");         $this->table->set_heading('id', 'product','category', 'actions');         $i = 0 + $offset;         foreach ($products $product){             ++$i;             $this->table->add_row($product->id, $product->title, $this->categories_model->get_by_id($product->category_id)->title,                 anchor('/admin/products/update/'.$product->id,'update',array('class'=>'update')).' '.                 anchor('/admin/products/delete/'.$product->id,'delete',array('class'=>'delete','onclick'=>"return confirm('are sure want delete product?')"))             );         }         $data['table'] = $this->table->generate();          //load template         $this->products_list();         $this->products_template();         $this->template->build('products/productlist', $data); 

here's model

function get_products($num, $offset) {     return $this->db->get($this->tbl_products, $num, $offset)->result();     } 

it generates links doesn't load next set of records..any corrections on code above?

thanks!

you should give page table, not full table. pagination fills links, doesn't make change on data, it's responsability.

please change:

        $products = $this->products_model->get_all(); 

with:

        $products = $this->products_model->get_page( $offset, $this->limit ); // it's not clear define limit. 

and in model make propper selection:

function get_page( $offset, $limit ){     return $this->db->get( $this->tbl_products, $limit, $offset )->result(); } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -