Welcome Guest, Not a member yet? Register   Sign In
pagination strang effect
#1

[eluser]italoc[/eluser]
i have this code:
Code:
$config['total_rows'] = $query->num_rows();
$config['per_page'] = '5';
$config['first_link'] = 'Inizio';
$config['last_link'] = 'Fine';
$this->pagination->initialize($config);

in the page i see the number of the single page (example 1 2 3 >) but i don't see the button 'Inizio' and 'Fine'.

is i change "$query->num_rows();" with an integer, i see the button 'Inizio' and 'Fine', but in this way i can't build pagination dynamiclly...

i have some suggestion ???

thanks
#2

[eluser]yogal[/eluser]
Hi,

I was recently battling with pagination too.

First of all, tell us what does this $query look like. Generally you shouldn't use the same query to:
a) limit your results with pagination
b) count the number of results and set them to $config['total_rows']

This can generate some problems as with every new limit you apply (you click 1 2 3 4 >) then $query->num_rows(); returns a smaller number.

What I have done is I made an additional function in my model which counts all the rows in a table.

Model:
Code:
function count_comments()
    {
        return $this->db->count_all_results($this->table);
    }

Controller:
Code:
$total_rows = $this->Guestbook_model->count_entries();

Then I'm using the second function to limit my results:

Model:

Code:
function get_comments_pagination($per_page, $offset)
    {
        $this->db->limit($per_page, $offset);
        $this->db->orderby('id', 'desc');
        return $this->db->get($this->table);
    }

Controller:

Code:
$query = $this->Guestbook_model->get_entries_pagination($this->config->item('per_page'), $offset);

I am not an advanced PHP programmer, maybe there is a better way of doing this, but if this helps - you know what your problem is.

I hope this is what you need Smile
#3

[eluser]italoc[/eluser]
thanks but i have 2 diffente query, 1 for totale row and 1 for populating the resulta

Code:
function poicomune() {
        $data = array();
        if (isset($_GET['comuneid'])) {
            $this->session->set_userdata('sponsorcomune', $_GET['comuneid']);
        }
        $this->load->library('pagination');
        $config['base_url'] = base_url().'index.php?c=external&m=poicomune';
        $this->db->select('*');
        $this->db->from('TB_POI_DEFINITION');
        $this->db->where('municipality_id', 70 );
        //$this->db->order_by("ID", "ASC");
        $query = $this->Guestbook_model->get_entries_pagination($this->config->item('per_page'), $offset);
        $total_rows = $this->Guestbook_model->count_entries();
        $config['total_rows'] = $total_rows;
        $config['per_page'] = '10';
        $config['first_link'] = 'Inizio';
        $config['last_link'] = 'Fine';
        $this->pagination->initialize($config);
        $this->load->library('parser');
        $this->db->select('*');
        $this->db->from('TB_POI_DEFINITION');
        $this->db->where('municipality_id', 70 );
        $this->db->order_by("ID", "ASC");
        ($this->input->get('per_page') == '') ? $limit = 0 : $limit = $this->input->get('per_page');
        $this->db->limit(10, $limit);
        $query = $this->db->get();
        $data['elencopoi'] = $query->result_array();
        //$this->load->view('external/elencopoi');
        $this->parser->parse('external/elencopoi', $data);
    }
    
    function count_comments()
    {
        return $this->db->count_all_results($this->table);
    }
    
    function get_comments_pagination($per_page, $offset)
    {
        $this->db->limit($per_page, $offset);
        $this->db->orderby('id', 'desc');
        return $this->db->get($this->table);
    }

can you help?
#4

[eluser]italoc[/eluser]
my Model

Code:
function get_count($filtro)
    {
           $this->db->select('*');
        $this->db->from('TB_SPONSOR');
        if ($filtro != 0) {
            $this->session->set_userdata('filtroselezionato', $filtro);
            $this->db->join('TB_POI_TB_CATEGORY', 'TB_POI_TB_CATEGORY.poi_id = TB_SPONSOR.poi');
            $this->db->join('TB_MACRO_CATEGORY', 'TB_MACRO_CATEGORY.CATEGORY = TB_POI_TB_CATEGORY.category_id');
            $this->db->where('TB_MACRO_CATEGORY.MACRO_CATEGORY', $filtro );
        } else {
            $this->session->set_userdata('filtroselezionato', 0);
        }
        $this->db->where('id_municipality', $this->session->userdata('sponsorcomune') );
        $this->db->where('TB_SPONSOR.type', 'associati' );

        return $this->db->count_all_results();
        
    }

My Controller

Code:
function sponsor() {
        $data = array();
        if (isset($_GET['comuneid'])) {
            $this->session->set_userdata('sponsorcomune', $_GET['comuneid']);
        }
        if (isset($_POST['filtro']) AND $_POST['filtro'] != 0) {
            $filtro = $_POST['filtro'];
        }else {
            $filtro = 0;
        }
        $this->load->library('pagination');
        $this->load->model('sponsorpag');
        $config['base_url'] = base_url().'index.php?c=external&m=sponsor';

        $config['total_rows'] = $this->sponsorpag->get_count($filtro);
        $config['per_page'] = '5';
        $config['first_link'] = 'Inizio';
        $config['last_link'] = 'Fine';
        $this->pagination->initialize($config);
        $this->load->library('parser');
        $this->db->select('*');
        $this->db->from('TB_SPONSOR');
        $this->db->join('TB_POI_DEFINITION', 'TB_POI_DEFINITION.id = TB_SPONSOR.poi');
        if (isset($_POST['filtro']) AND $_POST['filtro'] != 0) {
            $this->db->join('TB_POI_TB_CATEGORY', 'TB_POI_TB_CATEGORY.poi_id = TB_SPONSOR.poi');
            $this->db->join('TB_MACRO_CATEGORY', 'TB_MACRO_CATEGORY.CATEGORY = TB_POI_TB_CATEGORY.category_id');
            $this->db->where('TB_MACRO_CATEGORY.MACRO_CATEGORY', $this->input->post('filtro') );
        }
        $this->db->where('TB_SPONSOR.type', 'associati' );
        $this->db->order_by("TB_SPONSOR.ID", "desc");
        ($this->input->get('per_page') == '') ? $limit = 0 : $limit = $this->input->get('per_page');
        $this->db->limit(5, $limit);
        $query = $this->db->get();
        $data['sponsor'] = $query->result_array();
        $this->parser->parse('external/sponsor', $data);
    }

the same result, nothing changes

can you helpme?
#5

[eluser]yogal[/eluser]
Hmm,

I don't have a clue.

From what i can see, this should work.

I would suggest, for the research, simplify your queries - comment the join() statements.
Make it absolute minimum, 1 table and try to set up pagination then.

Make sure this
Code:
$this->sponsorpag->get_count($filtro);
returns a valid integer.

You can also set $config['total_rows'] to an integer, instead of db result, just to be sure its a number, then you should get numbers as well as 'First' and 'Last' links.

Also, try to move all your queries to the model.

EDIT:
This just came to my mind:
tell me how many numbers do you see in your pagination links ?
Code:
1 2 3
?
Code:
1 2 3 >
?

Because unless you have 4 or more pages of pagination, links like First and Last WILL NOT APPEAR!

I made a little research here.

Code:
$config['per_page'] = 10;
$config['total_rows'] = 30

no Last or First link,
but when i set total_rows to 40 links are showing Big Grin

So the problem might be as follows:
you have set $config['per_page'] = 5 and your $config['total_rows'] might be less than $config['per_page'] * 4 !

I hope this will help you!
#6

[eluser]Crimp[/eluser]
Code:
$config['num_links'] = 2;
The number of "digit" links you would like before and after the selected page number. For example, the number 2 will place two digits on either side, as in the example links at the very top of this page.

Try this one.




Theme © iAndrew 2016 - Forum software by © MyBB