0
Hello, good night!
I have two tables (Process and Movements). I need to generate a report with the Process data, along with the most recent progress. The query I wrote is returning me all the movements, repeating the process data. I’ve tried using $this->db->limit(1)
but so, only returns me 1 single process of several that should appear.
Query in Process Model_class:
function get_processos_ativos() {
$this->db->join('andamento', 'fkcodprocesso=codprocesso', 'left');
$this->db->select('*');
$this->db->order_by("str_to_date(andamento.dtandamento, '%d-%m-%Y')", 'DESC', FALSE);
return $this->db->get('processo')->result();
}
View code:
<?php foreach ($processo as $proc) : ?>
<div class="row">
<div class="col-md-4" >
<p><font size="2" face="helvetica"><strong>Autos nº:</strong> <a href="<?= base_url('processo/processoclicked/' . $proc->codprocesso) ?>" target="_self"><font size="2" face="helvetica"><?php echo $proc->nprocesso; ?></font></a></strong></font></p>
</div>
<div class="col-md-12">
<p><font size="2" face="helvetica"><strong>Comarca:</strong> <?php echo $proc->comarca; ?> - <?php echo $proc->numerovara; ?> <?php echo $proc->vara; ?></font></p>
</div>
</div>
<!-- ...vários outros dados da tabela processo. -->
Aqui é o dado onde eu quero que só apresente o último registro da tabela Andamentos:
<div class="row">
<div class="col-md-12" >
<p align="justify"><font size="2" face="helvetica"><strong>Último Andamento:</strong> <?php echo $proc->dtandamento; ?> - <?php echo $proc->descricao; ?></font></p>
</div>
</div>
<hr>
<?php endforeach; ?>
What query are you using to retrieve data from the database? I think that the solution will pass more easily by query than by PHP code itself.
– João Martins
@Joãomartins at the moment this one from the top, which brings me all the movements of each process, it occurs that I only need the last record of the table movements: Function get_processos_actives() ' $this->db->Join('progress', 'fkcodprocess=codprocess', 'left'); $this->db->select('*'); $this->db->order_by("str_to_date(progress.dtprogress, '%d-%m-%Y')", 'DESC', FALSE); Return $this->db->get('process')->result(); }
– Ramiro