PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 2, 2022

[FIXED] pagination with codeigniter not generating values

 March 02, 2022     codeigniter, pagination, php     No comments   

Issue

I have been trying to get this done, I want a pagination in my app. what i have now can only count the table rows. but when i click on the link to next batch of data, i receive a error 404.

Here is the code below. This is my Controller

public function index($page='dboard', $offset=0){
        $config['base_url'] = base_url() . 'manager/cplfc/';
        $config['total_rows'] = $this->db->count_all('users','attendance');
        $config['per_page'] = 1;
        $config['uri_segment'] = 1;
        $config['attributes'] = array('class' => 'pagination');

        // Init Pagination
        $this->pagination->initialize($config);


     $data['users'] = $this->ManagerModel->get_users(FALSE, $config['per_page'], $offset);

    if(!file_exists(APPPATH.'views/controls/manager/'.$page.'.php')){show_404();}
    $data['title']=ucfirst($page);
    $this->load->view('controls/manager/header');
    $this->load->view('controls/manager/'.$page,$data);
    $this->load->view('controls/manager/footer');
}

and this is the Model

public function get_users($id = FALSE, $limit = FALSE, $offset = FALSE){
    if($limit){
            $this->db->limit($limit, $offset);
        }
    if($id === FALSE){
        $this ->db->order_by('id', 'desc');
        $query = $this->db->get('users');
        return $query->result_array();
        }
    }

And this is my view

<div class="pagination pagination-centered">
                            <ul><li><?php echo $this->pagination->create_links(); ?></li></ul>
                        </div>

What can i do to make it work? Thanks in advance


Solution

All I needed was to set the URL Segment to "4" because the URL

$config = array();
$offset = $this->uri->segment(4);
$config['base_url'] = base_url() . 'manager/cplfc/';
$config['total_rows'] = $this->db->count_all('users','attendance');
$config['per_page'] = 1;
$config['uri_segment'] = 1;
$config['attributes'] = array('class' => 'pagination');


Answered By - Foozaweb
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing