• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CRUD and pagination problem after deleting records

Hi everyone.

I have a small problem in my crud.

Everything works perfectly, except for one small detail. I've choice to show 5 records per page.
Near to the name of the record in the list, i have the usual options such as update and delete.

When I delete the last record on the page, not showing previous page, but it remains on the same page giving message no records found, but showing pagination.

In practice, for example, i'm here:


deleting the last record of this page which is the third, not the url looks like this:


then going to page 2, but it remains as the first url shown above.

So I wrote in this way index method:

private $limit = 5;
public function index($order_column = '', $order_type = '', $offset = null)
  if(empty($offset)) $offset = 0;
  if(empty($order_column)) $order_column = 'id_category';
  if(empty($order_type)) $order_type = 'desc';
// This section of code improve the problem but not solve it
  $last_item = $this->db->get('categories')->num_rows();
  $how_many = $last_item - $offset;
  if($how_many < 1 && $offset != 0)
   $offset -= $this->limit;
// end
  $data['records'] = $this->categories_model->retrieve_categories($this->limit, $order_column, $order_type, $offset);
  $data['num_rec'] = $this->categories_model->record_count();
  $config['base_url'] = '' . base_url() . 'categories/index/'.$order_column.'/'.$order_type.'/';
  $config['total_rows'] = $data['num_rec'];
  $config['per_page'] = $this->limit;
  $config['uri_segment'] = 5;
     $config['num_links'] = 2;
  $config['full_tag_open'] = '<div id="pagination_middle">';
  $config['full_tag_close'] = '</div>';

  $data['pagination'] = $this->pagination->create_links();
  $data['offset'] = $offset;
  $data['order_column'] = $order_column;
  $data['order_type'] = $order_type;  
  $this->load->view('pages/categories_view', $data);

Mostly it works, because you see the second page, and I no longer have the message of no records found, but the url is:


and the page number in the paging links, is not highlighted in strong.

I need something like set_segment, but I know that does not exist.

Does anyone have an idea?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.