How to display data from three tables in a view?

1

I have three tables: Process, Progress and Costs: how do I display the data of the three in a View, and the Progress and Cost tables have as the foreign key the primary key of Process?

I made a foreach for each table, but it did not work, it duplicates the data.

        <div class="row">                         
            <strong>Sentença/Acórdão:</strong>
            <?php echo $processo[0]->sentenca; ?>         
        </div>
        <br>
        <div class="row">                         
            <p><font size="3" face="helvetica"><strong>Andamentos</strong></font></p>             
        </div>     
        <div class="row">        
            <div class="table-responsive">                                   
                <button type="submit" class="btn btn-primary hidden-print" data-toggle="modal" data-target=".addandamento"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>  
                <table class="table table-striped">                                         
                    <?php foreach ($processo as $proc) { ?>
                        <tr class="row">                                
                            <td width="14%"><font color="#000000" size="2" face="tahoma"><b><?= $proc->dtandamento; ?></b></font></td>
                            <td width="78%"><font color="#000000" size="2" face="tahoma"><b><?= $proc->descricao; ?></b></font></td>                            
                        </tr>  
                    <?php } ?>                    
                </table>
            </div>             
        </div>                  
        <div class="row">        
        <div class="table-responsive">                                   
            <button type="submit" class="btn btn-primary hidden-print" data-toggle="modal" data-target=".addandamento"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>  
            <table class="table table-striped">                                         
                <?php foreach ($processo as $proc) { ?>
                    <tr class="row">                                
                        <td width="14%"><font color="#000000" size="2" face="tahoma"><b><?= $proc->dtcustas; ?></b></font></td>
                        <td width="78%"><font color="#000000" size="2" face="tahoma"><b><?= $proc->descricao_custas; ?></b></font></td>                            
                    </tr>  
                <?php } ?>                    
            </table>
        </div>                       
    </div>

    
asked by anonymous 14.05.2018 / 05:21

1 answer

1

I do not know if I understand it right, but that you solve with the models, making a select that makes the JOINS between the three tables, something like:

SELECT * FROM Processo INNER JOIN Andamento ON Andamento.id_processo = Processo.id INNER JOIN Custas ON Custas.id_processo = Processo.id ...;

This using the functions of $this->db of codeigniter, such as:

    $this->db->from('Processo');
    $this->db->join('Andamento', 'Andamento.id_processo=Processo.id');
    $this->db->join('Custas', 'Custas.id_processo=Custas.id');

That will return an array, which you must iterate in your view.

    
16.05.2018 / 20:13