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

[eluser]mariuskmc[/eluser]
I have some concerns regarding the following situation

Information is extracted from the database correctly for all pages, links is running ok (except next) but pagination remains set on the first page.

Code:
$route['evenimente/categorie/(:any)/pagina/(:num)'] = "evenimente/categorie/$1";


Controller evenimente
Code:
function categorie($categorie, $ideveniment = FALSE, $eveniment = FALSE)
{
     if ( !empty($categorie) && empty($ideveniment) && empty($eveniment)) {
        $this->load->library('pagination');
        $categorie=$this->uri->segment(3);

        $totalevenimente=$this->Evenimente_model->getlistaevenimentecategorienumar($categorie);
        $config['base_url'] = base_url().'evenimente/categorie/'.$categorie.'/pagina';
        $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['per_page'] = '5';
        //$config['uri_segment'] = $this->uri->segment(3);
        $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(5));
        
        $data['paginare']=$this->pagination->create_links();    

    }

}

Recognize that this is the first time I dare to do pagination
#2

[eluser]mariuskmc[/eluser]
why if I have several uri, pagination it's working but current link remains set to the first link?

Quote:controller/function/$uri3
pagination ( controller/function/$uri3/5......50)


controller/function/$uri3/$uri4
pagination ( controller/function/$uri3/$uri4/5......50)

Someone can help me dig this issue?
#3

[eluser]mariuskmc[/eluser]
I'm a bit stuck now.
I now changed the pagination with jquery.

controller/index/ pagination works perfectly
controller/function/variable/ pagination same problems (pagination links remaining at the first link).

the only compromise solution is to make num_links more big then pages
something like $config ['num_links'] = '100';

Does anyone know what else I could do?
#4

[eluser]ramm[/eluser]
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();
    }

There's more stuff in my model, but you can see what i mean.
#5

[eluser]mariuskmc[/eluser]
Quote: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.
getlistaevenimentecategorienumar it's total rows $config['total_rows'] = count($totalevenimente);

Quote:$totalevenimente=$this->Evenimente_model->getlistaevenimentecategorienumar($categorie);
$config['total_rows'] = count($totalevenimente);

Pagination returns the information correctly, the pagination links are created correctly .... if I click on a number from list, values are returned correctly
but pagination links still remain set on the first page .... and if I have more pages can also visit the numbers displayed and the last page.

Next_page is always the same link (second page) and first page(1) is always active
#6

[eluser]ramm[/eluser]
Still missing LIMIT and OFFSET in the model. Pagination don't have any problem, but every page is receiving the same records because there's no OFFSET in the SELECT query.
#7

[eluser]mariuskmc[/eluser]
i receiving diferent records...

only pagination links from bottom or top remain always set to first page

this is for records list
Code:
$data['lista_evenimente']=$this->Evenimente_model->getlistaevenimentecategorie($categorie, $config['per_page'], $this->uri->segment(4));

if I set the offset and limit in total_rows I do not think it's ok ... will not know how many pages are there to make pagination

I have the same code to index, a list of all records from all categorya and it's working
but when i make a list of all records from category i have this problem

I will put online application
#8

[eluser]ramm[/eluser]
Can you post your model?
#9

[eluser]mariuskmc[/eluser]
you got links in pm?
#10

[eluser]mariuskmc[/eluser]
Model
Code:
function getlistaevenimentecategorie($categorie, $num, $offset) {
    $data = array();
    $categorie = str_replace('_', ' ', $categorie);
    $this->db->select('evenimentecategorie.idevenimentecategorie,
  evenimentecategorie.numeevenimentecategorienav,
  evenimentecategorie.numeevenimentecategorie,
  evenimente.id,
  evenimente.evenimentecategorie,
  evenimente.titluevenimentenavigare,
  evenimente.titlu,
  evenimente.subtitlu,
  evenimente.descriere,
  evenimente.pozaexterior,
  evenimente.data');
    $this->db->from('evenimente');    
    $this->db->join('evenimentecategorie','evenimentecategorie.idevenimentecategorie = evenimente.evenimentecategorie','inner');
    $this->db->where('evenimentecategorie.numeevenimentecategorienav', $categorie);    
    //$this->db->group_by('evenimente.id');
    $this->db->order_by('evenimente.data','DESC');
    $this->db->limit($num, $offset);
        $q = $this->db->get();
        if ($q->num_rows()>0) {
            foreach ($q->result() as $row){
            $data[]= $row;
            }
            return $data;
        }
    }




function getlistaevenimentecategorienumar($categorie) {
    $data = array();
    $categorie = str_replace('_', ' ', $categorie);
    $this->db->select('evenimentecategorie.idevenimentecategorie,
  evenimentecategorie.numeevenimentecategorienav,
  evenimentecategorie.numeevenimentecategorie,
  evenimente.id');
    $this->db->from('evenimente');    
    $this->db->join('evenimentecategorie','evenimentecategorie.idevenimentecategorie = evenimente.evenimentecategorie','inner');
    $this->db->where('evenimentecategorie.numeevenimentecategorienav', $categorie);    
    $this->db->group_by('evenimente.id');
        $q = $this->db->get();
        if ($q->num_rows()>0) {
            foreach ($q->result() as $row){
            $data[]= $row;
            }
            return $data;
        }
    }




Theme © iAndrew 2016 - Forum software by © MyBB