Welcome Guest, Not a member yet? Register   Sign In
Pagination does not show pages links.
#1

[eluser]Unknown[/eluser]
Hello,

Im having problems with pagination to work right. The adressing works fine but cant force the pagination links to display

Here is the controller
Code:
public function listing(){
        $data['content']='contentList';
        $data['row']="";

        $config['per_page'] = 10;
        $config['num_links'] = 5;
        $config['full_tag_open'] = '<p>';
        $config['full_tag_close'] = '</p>';

        if($this->uri->segment(2)!=""){
            $this->load->model('datamodel');
            $data['row']=$this->datamodel->getByOs($this->uri->segment(2), $config['per_page'],$this->uri->segment(3));
            $config['base_url'] = base_url().'list/'.$this->uri->segment(2);
        }
        /*
        if($this->uri->segment(2)!="" && $this->uri->segment(3)!=""){
            $this->load->model('datamodel');
            $data['row']=$this->datamodel->getByCat($this->uri->segment(2), $this->uri->segment(3));
            $config['base_url'] = base_url().'list/'.$this->uri->segment(2).'/'.$this->uri->segment(3);
        }
        if($this->uri->segment(2)!="" && $this->uri->segment(3)!="" && $this->uri->segment(4)!=""){
            $this->load->model('datamodel');
            $data['row']=$this->datamodel->getBySubCat($this->uri->segment(2), $this->uri->segment(3), $this->uri->segment(4));
            $config['base_url'] = base_url().'list/'.$this->uri->segment(2).'/'.$this->uri->segment(3).'/'.$this->uri->segment(4);
        }
        */
        $config['total_rows'] = count($data['row']);

        $this->pagination->initialize($config);
        
        $this->load->view('main', $data);
            
    }

Here is model
Code:
public function getByOs($os, $num, $offset){
            //$q = $this->db->query("SELECT * FROM programs WHERE osForDb='".$os."'");

            $q = $this->db->get_where('programs', array('osForDb' => $os), $num, $offset);
            
            if($q->num_rows()>0){
                foreach($q->result() as $row){
                    $data[]=$row;
                }
                return $data;
            }

        }

and here is the view
Code:
if(!empty($row)){
        foreach($row as $r){
            echo $r->name."<br/>";
        }
    }
    
    echo $this->pagination->create_links();

Im rly newbie to codeigniter yet, guess its some totally dumb thing. Thx for help in advance.
#2

[eluser]Unknown[/eluser]
Hi there, copy and paste this into your controller

Code:
//You need to load the libraries before you can use them
$this->load->library('pagination');

$data['content']='contentList';
        $data['row']="";

        $config['per_page'] = 10;
        $config['num_links'] = 5;
        $config['full_tag_open'] = '<p>';
        $config['full_tag_close'] = '</p>';

        if($this->uri->segment(2)!=""){
            $this->load->model('datamodel');
            $data['row']=$this->datamodel->getByOs($this->uri->segment(2), $config['per_page'],$this->uri->segment(3));
            $config['base_url'] = base_url().'list/'.$this->uri->segment(2);
        }
        /*
        if($this->uri->segment(2)!="" && $this->uri->segment(3)!=""){
            $this->load->model('datamodel');
            $data['row']=$this->datamodel->getByCat($this->uri->segment(2), $this->uri->segment(3));
            $config['base_url'] = base_url().'list/'.$this->uri->segment(2).'/'.$this->uri->segment(3);
        }
        if($this->uri->segment(2)!="" && $this->uri->segment(3)!="" && $this->uri->segment(4)!=""){
            $this->load->model('datamodel');
            $data['row']=$this->datamodel->getBySubCat($this->uri->segment(2), $this->uri->segment(3), $this->uri->segment(4));
            $config['base_url'] = base_url().'list/'.$this->uri->segment(2).'/'.$this->uri->segment(3).'/'.$this->uri->segment(4);
        }
        */
        $config['total_rows'] = count($data['row']);

        $this->pagination->initialize($config);
        
//Save the pagination links into a $data variable
$data['links']=$this->pagination->create_links()
        $this->load->view('main', $data);

And after that delete the line in your view that says
Code:
echo $this->pagination->create_links();
and replace it with
Code:
echo $links;

You see, you need to load the libraries in your controller, so you can use them, otherwise all your $config data will be going nowhere, this will probably give you errors too.. Try this, it should fix it

You should probably check the documentation about the pagination library, it will help you a lot Check it out here
#3

[eluser]agdelacruz02[/eluser]
Hi, I'm also having problems with my pagination, there was an error when I click on the "[2]" or ">" links the error says
Quote:The requested URL /2 was not found on this server.
. Can you help me in this pls. tnx.




Theme © iAndrew 2016 - Forum software by © MyBB