Welcome Guest, Not a member yet? Register   Sign In
Pagination doesnt appear
#1

[eluser]Balistix[/eluser]
Hi there, I am very much new to php and code igniter itself. Recently I followed some tutorials on pagination, but it doesn't work as it should. I suspect its probably my coding error (most proobably) , can anyone be helpful enough to check this up for me. Thanks.

My controller

Code:
<?php

class gallery extends Controller {


    function index()
    {
        $this->load->library('pagination');
        $config['base_url'] = 'http://localhost/ci_avatar/index.php/gallery/index/';
        $config['total_row'] = $this->db->get('ci_images')->num_rows();
        $config['per_page'] = 9;
        $config['num_links'] = 20;
        

        $this->pagination->initialize($config);
        echo $this->pagination->create_links();

        $data['records'] = $this->db->get('ci_images', $config['per_page'], $this->uri->segment(3));
        $data['main_content'] = 'gallery_view';
        $this->load->view('includes/template', $data);


    }

}
?>

This is my view for testing purpose

Code:
<div id="container">

    <h1>This is the pagination</h1>

    &lt;?php
        
        echo $this->table->generate($records);
        echo $this->pagination->create_links();

    ?&gt;

</div>

This is how it turns out.

[Image: http://img138.imageshack.us/img138/4275/testjo.png]

Alternatively I tried this after seeing one of the thread.

Code:
&lt;?php

class gallery extends Controller {


    function index()
    {
        $this->load->library('pagination');
        $config['base_url'] = current_url();
        $config['total_row'] = $this->db->get('ci_images')->num_rows();
        $config['per_page'] = 9;
        $config['num_links'] = 20;
        

        $this->pagination->initialize($config);
        echo $this->pagination->create_links();

        $data['records'] = $this->db->get('ci_images', $config['per_page'], $this->uri->segment(3));
        $data['main_content'] = 'gallery_view';
        $this->load->view('includes/template', $data);


    }

}
?&gt;

I heard it might be the base url problem, but again, only the pagination part does not appear. Hopefully someone can help me understand what is the problem. Thanks in advance.
#2

[eluser]InsiteFX[/eluser]
You can read this article...

CodeIgniter Pagination

InsiteFX
#3

[eluser]Balistix[/eluser]
Thanks for your reply, im watching it now, hopefully it helps. If it matters, im using xampp, on windows machine with not .httacces.
#4

[eluser]InsiteFX[/eluser]
I am running XAMPP 1.7.3 Windows Vista PHP 5.3.1 with no .htaccess

You may need the following:

$config['uri_segment'] = 3;

The 3 will be your last uri segment number.

InsiteFX
#5

[eluser]Balistix[/eluser]
Tried and doesnt work. I actually followed the coding style of Jeffrey Way without changing any important part, so im stumped at why mine does not work only at the pagination part. Where I did not change anything to the code.

Pagination Screencast

Just finished streaming all the screencast you gave me yesterday when I woke up this morning. Going to have a look soon.
#6

[eluser]pickupman[/eluser]
It looks like you maybe passing false to your query since the 3rd uri segment may not be set.
Change
Code:
$data['records'] = $this->db->get('ci_images', $config['per_page'], $this->uri->segment(3));

To:
Code:
$data['records'] = $this->db->get('ci_images', $config['per_page'], $this->uri->segment(3,0));

This will pass an offset of 0 if the 3rd segment is not present
#7

[eluser]Balistix[/eluser]
But that $data['records'] query is for generating table not pagination. But I'll try your method.

edited : tried, doesnt work Smile
#8

[eluser]pickupman[/eluser]
You also need to change:
Code:
$config['total_row'] = $this->db->get('ci_images')->num_rows();

To
Code:
$config['total_rows'] = $this->db->get('ci_images')->num_rows();

You were missing the "s" in total_rows. You also need the part I posted above, otherwise you are never passing an offset to start from.
#9

[eluser]Balistix[/eluser]
Oh my.. I guess i missed that out. It worked now. Thanks for your help and sorry for the time wasted on silly mistakes.




Theme © iAndrew 2016 - Forum software by © MyBB