Welcome Guest, Not a member yet? Register   Sign In
Table Generating repeated columns
#1

[eluser]hvalente13[/eluser]
I'm trying to get CI to work in the office, but after some time, of trying to do something simple I have to ask.

After connecting to sqlite database, i use pagination and table libraries, and the most odd thing happens: I get repeated columns values.

Instead of getting only a single value for each column i get the same value twice.

The code

Controller:

Code:
class Ocorrencias extends Controller {

    function __construct()
    {
        parent::Controller();

        $this->output->enable_profiler(TRUE);
        $this->load->helper('url');
        $this->load->database();
    }
    
    function index()
    {  
        $this->load->library('pagination');

        $config['base_url'] = base_url().'index.php/ocorrencias/index/';
        $config['total_rows'] = $this->db->count_all('t_ocorrencia');
        $config['per_page'] = '10';
        $config['full_tag_open'] = '<p>';
        $config['full_tag_close'] = '</p>';

        $this->pagination->initialize($config);
        $this->load->model('ocr_model');
        $data['results'] = $this->ocr_model->get_ocrs($config['per_page'],$this->uri->segment(3));
        $this->load->library('table');
        $this->table->set_heading('Data', 'Tipo Ocr.', 'Paciente', 'Local', 'Participante');
        $this->table->set_caption('Ocorrências');
        $data['titulo']="Dial PROg";

        $this->load->view('ocr', $data);

    }
}

View
Code:
&lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
&lt;link rel="stylesheet" href='&lt;?php echo base_url(); ?&gt;include/estilos.css' type="text/css" media="screen, projection" /&gt;
&lt;title&gt;
&lt;?=$titulo?&gt;
&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;?php echo $this->table->generate($results); ?&gt;

&lt;?php echo $this->pagination->create_links(); ?&gt;

&lt;/body&gt;
&lt;/html&gt;

And finaly the model
Code:
class ocr_model extends Model {
  function __construct(){
    parent::Model();
  }

  function get_ocrs($num, $offset) {
    $this->db->select('t_ocorrencia.data as data, t_ocrtipo.tipo_ocr as tipo, (t_pacientes.nome || ", " || t_pacientes.apelido) as nome, t_ocrlocal.local_ocr as local, t_funcionario.funcionario as funcionario');
    $this->db->from('t_ocorrencia');
    $this->db->join('t_ocrlocal', 't_ocrlocal.localid = t_ocorrencia.local_ocr');
    $this->db->join('t_ocrtipo', 't_ocrtipo.tipoocrid = t_ocorrencia.tipo_ocr');
    $this->db->join('t_pacientes', 't_pacientes.pacienteid = t_ocorrencia.pacienteid');
    $this->db->join('t_funcionario', 't_funcionario.funcionarioid = t_ocorrencia.participante');
    $query = $this->db->get('', $num, $offset);
    return $query;
  }
}

Some can help?

Thanks in advance
#2

[eluser]ELRafael[/eluser]
First off all, try to debug sql query. something like that joe
Code:
$this->db->last_query()

see if this query is ok. i had some troubles, and when i saw in the db, is the fck sql!!!



ps: vc não é brazuca não, é??
#3

[eluser]hvalente13[/eluser]
I can solve the problem by doing like this:

Code:
foreach($results->result() as $row){

   $editar=anchor("admin","<img src='".base_url()."imgs/notas.png' border='0' />","title='Editar'");
   $apagar=anchor("print","<img src='".base_url()."imgs/print.png' border='0' />","title='Imprimir'");
   $this->table->add_row($row->data,$row->tipo,$row->nome,$row->local,$row->funcionario,$editar,$apagar);

}

echo $this->table->generate();

The sql statement is ok, i've tested it in sqlitemanger and it gives the result i expected.

I'm portuguese in Portugal... from the original ones... lol Smile
#4

[eluser]ELRafael[/eluser]
Que bom que resolveu!!!

Patrício, você é que lugar de Portugal??
#5

[eluser]hvalente13[/eluser]
Perto do Porto

Santa Maria da Feira, já ouviste falar?
#6

[eluser]ELRafael[/eluser]
Distrito de Aveiro, não? Alguns familiares (bem distantes) foram pra Aveiro!

Conheço pelo Europarque, só :cheese:
#7

[eluser]hvalente13[/eluser]
É perto de onde vivo...

Já cá estiveste?




Theme © iAndrew 2016 - Forum software by © MyBB