• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Porblem with pagination

#1
[eluser]Unknown[/eluser]
hi,
I have a problem with pagination. At least, with link generated. When I going to page "2", the messages display correctly (and on pages 3,4,5 etc...) but the links are not initialized as if I was on the first page.

Controller:
Code:
<?php
public function sujet($slug, $numero_page = 1){

        $this->load->library('form_validation');

        $this->form_validation->set_rules('contenu', '"Message"', 'trim|required|xss_clean');

        if($this->form_validation->run()) {

            $result = $this->forum->ajouter_message($slug, $this->session->userdata('id_membre'), $_POST['contenu']);

            redirect('forum/sujet/'.$slug);

        }

        // Pagination

        $nb_messages_total = $this->db->where('slug_sujet', $slug)->get('forum_messages')->num_rows();

        if($numero_page > 1){
            if($numero_page <= $nb_messages_total){
                $nb_messages = intval($numero_page);
            }else{

                $nb_messages = 1;
            }
        }else{
            $nb_messages = 1;
        }

        $config['base_url'] = site_url().'forum/sujet/'.$slug.'/';
         $config['total_rows'] = $nb_messages_total;
         $config['per_page'] = self::NB_PAR_PAGE;
         $config['num_links'] = '4';
        $config['first_link'] = "Première";
        $config['last_link'] = "Dernière »";

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

        $data['pagination'] = $this->pagination->create_links();

        $data['messages'] = $this->forum->messages($slug, self::NB_PAR_PAGE, $nb_messages-1);

        $data['id_cat'] = $this->forum->id_cat_p_sujet($slug);

        $data['slug'] = $slug;

        $this->layout->view('Forum/sujet_liste_messages', $data);

    }
    ?&gt;

Model:
Code:
&lt;?php
    public function messages($slug_sujet, $nb, $debut = 0){

        if(!is_integer($nb) || $nb < 1 || !is_integer($debut) || $debut < 0){
            return false;
        }

        return $this->db->select('*')
                ->select("DATE_FORMAT(date_creation, '%d/%m/%Y à %H:%i') AS date_creation", FALSE)
                ->select("DATE_FORMAT(date_modification, '%d/%m/%Y à %H:%i') AS date_modification", FALSE)
                ->select("DATE_FORMAT(date_inscription, '%m/%Y') AS date_inscription", FALSE)
                ->from($this->table['messages'])
                ->join($this->table['membres'], 'forum_messages.id_auteur = membres.id', 'left')
                ->where('slug_sujet', $slug_sujet)
                ->limit($nb, $debut)
                ->get()
                ->result();

    }
?&gt;


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.