Limit the number of rows in the second table?

0

Hello, good evening!

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 steps, causing the process data to be repeated. I've tried using $this->db->limit(1) but so, it only returns me 1 single process of several that should appear.

Query in the Model Model_Process:

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; ?>  
    
asked by anonymous 28.06.2018 / 23:06

1 answer

1

If your goal is to limit the results without any further conditions, you were on the right path and you should use

$this->db->limit(N) % being N the number of rows you want to display

    
29.06.2018 / 12:17