0
Hello, I have a problem paging, the links of the pagination are displayed normally, but regardless of the page I go, the results are always the same, IE, does not change.
Below is the Controller function
public function index()
{
if ( ! $this->ion_auth->logged_in() OR ! $this->ion_auth->is_admin())
{
redirect('auth/login', 'refresh');
}
else
{
/* Título da Página */
$this->page_title->push(lang('menu_produtos'));
$this->data['pagetitle'] = $this->page_title->show();
/* Breadcrumbs */
$this->data['breadcrumb'] = $this->breadcrumbs->show();
/* Paginação */
$this->load->library('pagination');
$config['base_url'] = base_url('admin/produtos/index');
$config['total_rows'] = $this->produtos_model->count('produtos');
$config['per_page'] = 3;
$this->pagination->initialize($config);
/* get produtos */
//$this->data['produtos'] = $this->produtos_model->get('produtos','id,descricao,preco_compra,preco_venda,estoque,estoque_min','');
$this->data['produtos'] = $this->produtos_model->get('produtos','id,descricao,preco_compra,preco_venda,estoque,estoque_min','',$config['per_page'],$this->uri->segment(3));
/* Carrega Template */
$this->template->admin_render('admin/produtos/index', $this->data);
}
}
Below is the Model
public function get($table,$fields,$where='',$perpage=0,$start=0,$one=false,$array='array'){
$this->db->select($fields);
$this->db->from($table);
$this->db->order_by('id','desc');
$this->db->limit($perpage,$start);
if($where){
$this->db->where($where);
}
$query = $this->db->get();
$result = !$one ? $query->result() : $query->row();
return $result;
}
public function count($table){
return $this->db->count_all($table);
}
Table
id
INT(11) NOT NULL AUTO_INCREMENT,
descricao
VARCHAR(80) NOT NULL,
preco_compra
DECIMAL(10,2) NULL DEFAULT NULL,
preco_venda
DECIMAL(10,2) NOT NULL,
estoque
INT(11) NOT NULL,
estoque_min
INT(11) NULL DEFAULT NULL,
Have you tried debugging the sql statement to see if it is being generated correctly? Use $this->db->last_query() to retrieve the string from the SQL statement. Then you take this string and do a test in a DBMS (phpmyadmin, for example) to see what will be returned.
– Jonathan Lamim Antunes
I did not debug, and I confess that I do not know how to use last_query. .
– Wagner Fillio