Welcome Guest, Not a member yet? Register   Sign In
Routing or pagination problems
#11

[eluser]mariuskmc[/eluser]
Controller
Code:
/* --------------*/

function categorie($categorie = FALSE, $ideveniment = FALSE, $eveniment = FALSE)
     {
        
     if ( !empty($categorie) && !empty($ideveniment) && !empty($eveniment)) {
        echo'bla bla';
                  
         }
        

    if ( !empty($categorie) && empty($ideveniment) && empty($eveniment)) {
        
         $data['meta_titlu_numar']='0';
        
         //
         $data['detalii_categorie']=$this->Evenimente_model->getdetaliicategorie($categorie);
        
         //
         $data['navigare_categorii']=$this->Evenimente_model->getAllnavigarecategorii();  

        $this->load->library('pagination');
        
        
        $totalevenimente=$this->Evenimente_model->getlistaevenimentecategorienumar($categorie);
        $config['base_url']= base_url().'evenimente/evenimente_categorie/'.$categorie.'/';
        
        
        $config['total_rows'] = count($totalevenimente);
        
            
        $config['first_tag_open'] = '<li>';
        $config['first_link'] = 'Prima pagina';
        $config['first_tag_close'] = '</li>';
        
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        
        $config['next_tag_open'] = '<li>';
        $config['next_link'] = 'Pagina urmatoare';
        $config['next_tag_close'] = '</li>';
        
        $config['prev_tag_open'] = '<li>';
        $config['prev_link'] = 'Pagina anterioara';
        $config['prev_tag_close'] = '</li>';
        
        $config['last_tag_open'] = '<li>';
        $config['last_link'] = 'Ultima pagina';
        $config['last_tag_close'] = '</li>';
        
        $config['cur_tag_open'] = '<li class="active">';
        $config['cur_tag_close'] = '</li>';

        $config['suffix'] = '.html';
        
        //$config['num_links'] = '100';
        $config['per_page'] = '10';
        $config['full_tag_open'] = '<ul id="pagination-digg">';
        $config['full_tag_close'] = '</ul>';
        
        $this->pagination->initialize($config);
        $data['lista_evenimente']=$this->Evenimente_model->getlistaevenimentecategorie($categorie, $config['per_page'], $this->uri->segment(4));
        
        $data['paginare']=$this->pagination->create_links();    
        //load the model and get results
        
        $data['meta']="evenimente/meta";
         $data['main']="evenimente/pagina_categorie";
         $data['meniu_stanga']="evenimente/meniu_stanga";
         $data['meniu_dreapta']="evenimente/meniu_dreapta";
        
         $data['template']="include/templates_3col";
         $this->load->view('include/template',$data);
         }

     }    

/* --------------*/
     function evenimente_categorie($categorie)
     {

        $this->load->library('pagination');
        
        
        $totalevenimente=$this->Evenimente_model->getlistaevenimentecategorienumar($categorie);
        $config['base_url'] = base_url().'evenimente/evenimente_categorie/'.$categorie.'/';
        
        //$config['total_rows'] = 50;
        $config['total_rows'] = count($totalevenimente);
        
            
        $config['first_tag_open'] = '<li>';
        $config['first_link'] = 'Prima pagina';
        $config['first_tag_close'] = '</li>';
        
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        
        $config['next_tag_open'] = '<li>';
        $config['next_link'] = 'Pagina urmatoare';
        $config['next_tag_close'] = '</li>';
        
        $config['prev_tag_open'] = '<li>';
        $config['prev_link'] = 'Pagina anterioara';
        $config['prev_tag_close'] = '</li>';
        
        $config['last_tag_open'] = '<li>';
        $config['last_link'] = 'Ultima pagina';
        $config['last_tag_close'] = '</li>';
        
        $config['cur_tag_open'] = '<li class="active">';
        $config['cur_tag_close'] = '</li>';
        
        $config['suffix'] = '.html';

       //$config['num_links'] = '100';
        $config['per_page'] = '10';
        //$config['uri_segment'] = $this->uri->segment(3);
        $config['full_tag_open'] = '<ul id="pagination-digg">';
        $config['full_tag_close'] = '</ul>';
        
        //$config['display_pages'] = FALSE;
        $this->pagination->initialize($config);
        $data['lista_evenimente']=$this->Evenimente_model->getlistaevenimentecategorie($categorie, $config['per_page'], $this->uri->segment(4));
        
        $data['paginare']=$this->pagination->create_links();    
        //load the model and get results
        
         $_html=$this->load->view('evenimente/rezultate_evenimente' , $data, TRUE);
        echo $_html;

     }
#12

[eluser]ramm[/eluser]
See how you have set in your model:
Code:
$this->db->limit($num, $offset);

For the first function but not the second.
#13

[eluser]mariuskmc[/eluser]
i can set $config['total_rows'] = any number;

getlistaevenimentecategorienumar($categorie) must return total row ... not total row from 10 to 20

not working with $this->db->limit($num, $offset);

getlistaevenimentecategorienumar ($categorie, $num, $offset)
will return a single block of results, pagination will be canceled because he does not see other pages
#14

[eluser]ramm[/eluser]
Every page has it's own SELECT with offset and limit, it doesn't affect the total rows. In my application works with no problems.
#15

[eluser]mariuskmc[/eluser]
[quote author="ramm" date="1299012545"]I think you are missing the "limit" and "offset" in your "getlistaevenimentecategorienumar" function. That is what tells the model where every page starts and ends.
Code:
function getlistaevenimentecategorienumar($options = array())
{
    if(isset($options['limit']) && isset($options['offset']))
    {
        $this->db->limit($options['limit'], $options['offset']);
    }

        $query = $this->db->get('your_table');

        if(isset($options['count'])) return $query->num_rows();

        return $query->result();
    }
[/quote]
In your function you dont have limit and offset for count option.
And when you call total_row = count(something) OR something = $this->model->function(); you dont put limit

I made separate function for counting - you are using the same with options array... in this case.

you see the online version ... works ok except the links that remain set on first page
#16

[eluser]ramm[/eluser]
No, because COUNT will count everything, not just the limit i'm selecting.

I checked the links and i don't understand how are you making that work if the URL doesn't change, and you are not using the config['uri_segment'] to know in what page you are.
#17

[eluser]mariuskmc[/eluser]
with ajax

in first function "categorie" with category selected i call first page of list, then other pages of pagination are from second function "evenimente_categorie"

open in new window the link of pagination from pages with my problem

or see in status bar
#18

[eluser]Unknown[/eluser]
I know this is an old post, but I just experienced this issue and finally resolved the problem by examining the pagination library.

The scenario:

Your pagination links are generated.
Your links work flawlessly when you click, and return data without issue.

The problem:

Your pagination 'active/current' link is stuck on the first link.
While data is returning properly when you click other links, it never makes those clicked links the active link, even though the data is returning properly.

The solution:
By default the pagination library is configured to read this uri segment, code taken directly from CI 2.1 system/libraries/Pagination.php.
Code:
var $uri_segment  = 3;

In your config array you need to include,
Code:
$config['uri_segment'] = #

Where the '#' is equal to the uri segment of your pagination.
In reference to the original posters issue, his pagination uri_segment would be 4 according to his config['base_url'] below:
Code:
$config['base_url']= base_url().'evenimente/evenimente_categorie/'.$categorie.'/';

Because he failed to set $config['uri_segment'] = 4; the pagination library was looking at the third segment which was a string indicating which category a person was viewing. Thus breaking the updating of the pagination links to indicate which page he was on.

Hope this helps anyone else that gets stuck on this nonsense. Pounded my head against the desk for a good 30 minutes wondering why it worked with no filters using segment 3 and why it broke when I pushed my own pagination segment to 7 while adding filters between.




Theme © iAndrew 2016 - Forum software by © MyBB