1
I have a code that takes data from the database and shows them in a table. I need it to appear only the first two records. For this I put a limit on my code. Only it is not limiting, but taking the total and decreasing by the number.
EX: $this->db->limit(0,5);
In this code he would take the total number of records minus the five that’s in the code and show what’s left. I need him to take the total and show only two of these records.
MODEL:
public function getDoisLaudos($vei, $est, $urb, $rur, $aca) {
$this->datatables->select('ls.la_id, ls.la_tipo, ls.la_data, usu.usr_nome, disp.dsp_nome, ls.la_densidade, ls.la_nivel, ls.la_zona, ls.la_status');
$this->datatables->from('ls');
$this->datatables->join('usu', 'ls.usr_id = usu.usr_id');
$this->datatables->join('disp', 'ls.dsp_id = disp.dsp_id');
$this->datatables->join('empresa', 'empresa.emp_id = usu.emp_id');
$this->datatables->where('usu.emp_id = ' . $this->session->userdata('emp_id') . ' AND usu.usr_nivel<>0');
$this->db->limit(0,5);
$this->datatables->unset_column('ls.la_id');
$this->datatables->unset_column('ls.la_status');
$this->datatables->add_column('Ações', '$1', 'get_buttons_laudos(ls.la_id, ls.la_status, ls.la_tipo,' . $aca . ')');
$this->datatables->edit_column('ls.la_tipo', '$1', 'trataLauTipo(ls.la_tipo,' . $vei . ',' . $est . ')');
$this->datatables->edit_column('ls.la_data', '$1', 'tratarDataHora(ls.la_data)');
$this->datatables->edit_column('ls.la_zona', '$1', 'trataLauPerimetro(ls.la_zona,' . $urb . ',' . $rur . ')');
$this->datatables->edit_column('ls.la_status', '$1', 'trataLauStatus(ls.la_status)');
return $this->datatables->generate();
}
Controller:
public function generateTable() {
echo $this->ML->getDoisLaudos($this->lang->line("con_laudo_tip_insp_v"), $this->lang->line("con_laudo_tip_insp_e"), $this->lang->line("con_laudo_per_insp_u"), $this->lang->line("con_laudo_per_insp_r"), $this->lang->line("con_laudo_acoes_insp"));
}
I see you’re using the library https://github.com/IgnitedDatatables/Ignited-Datatables . This library I use for a table when you have a lot of data and you need ajax that will do that limit by "behind the scenes". I would advise to change things a little, if you just really want to show two records, so I imagine you do not need to bring these two data by ajax, so why not use do the normal way? But then there’d be some changes.
– Marcelo Diniz