Welcome Guest, Not a member yet? Register   Sign In
I have a little error with pagination class
#1

(This post was last modified: 01-03-2017, 11:00 AM by CoalsPlay.)

Hello, I have an error with my pagination.

I am developing a news system with comments, but when I try to page the comments that have each news, when accessing it, the pager goes to the last button in the back and I have no idea why. If you could help me I would be very grateful.

I leave a few pictures:

Controller:
PHP Code:
        // Pagination

        
$config['base_url'] = base_url().'noticia/'.$idNew.'/';
        
$config['total_rows'] = $this->admin_m->numCommentsId($idNew);
        
$config['per_page'] = 1;
        
$config['first_url'] = base_url().'noticia/'.$idNew.'/1'
        (
$this->uri->segment(3)) ? $page = ($this->uri->segment(3)-1)*$config['per_page'] : $page 1;

        
$data['data_comments'] = $this->admin_m->getCommentsId($idNew$config['per_page'], $page);

        
$this->pagination->initialize($config);
        
        
$data['pagination'] = $this->pagination->create_links();
        
// End Pagination 



Mode
PHP Code:
    public function getCommentsId($idNew$per_page$page)
    {
        
$sql $this->db->query("SELECT * FROM comentarios JOIN usuarios ON comentarios.autorComentario = usuarios.usuario                                                    WHERE idNoticiaComentario = '$idNew'
                                                           ORDER BY idComentario DESC LIMIT 
$page$per_page ");

        if(
$sql->num_rows() > 0)
        {
            return 
$sql->result();
        }else{
            return 
NULL;
        }
    }

    public function 
numCommentsId($idNew)
    {
        
$sql $this->db->select('idComentario')
                        ->
from('comentarios')
                        ->
where('idNoticiaComentario'$idNew);

        return 
$sql->count_all_results();
    } 
Routes:
PHP Code:
$route['default_controller'] = 'inicio';
$route['logout'] = 'login/logout';
$route['inicio/noticias/(:num)'] = 'inicio/index/noticias/$1';
$route['noticia/(:num)'] = 'noticia/index/$1';
$route['noticia/(:num)/(:num)'] = 'noticia/index/$1/$2';
$route['perfil/(:any)'] = 'perfil/index/$1';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE

Gif of the error:
[Image: 929712b27e038d7424660fa43789012b.gif]
Many thanks to all in advance. A greeting!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB