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:
Many thanks to all in advance. A greeting!