Show query in table

0

I have my functional sql query. If I print it with print_r it gives me all the information I need, which are only 5 records with 3 data:

Array ( [0] => stdClass Object ( [fecha_del_deposito] => 2018-05-08 [importe] => 60 [tipo_de_pago] => Mensualidad ) [1] => stdClass Object ( [fecha_del_deposito] => 2018-05-08 [importe] => 300 [tipo_de_pago] => Mensualidad ) [2] => stdClass Object ( [fecha_del_deposito] => 2018-05-08 [importe] => 360 [tipo_de_pago] => Mensualidad ) [3] => stdClass Object ( [fecha_del_deposito] => 2018-05-08 [importe] => 929 [tipo_de_pago] => Credito ) [4] => stdClass Object ( [fecha_del_deposito] => 2018-05-08 [importe] => 465 [tipo_de_pago] => Credito ) )

And I want to show it in a table, but I do not know how to do it dynamically since what I could do is put it "manually" occupying a lot of space and nothing practical, here an example of only what I've done for a Registration only:

<div class="tableFixHead">
  <table class="table table-striped">
    <thead>
      <tr>
        <th class="col-xs-2">Fecha del pago</th>
        <th class="col-xs-2">Monto</th>
        <th class="col-xs-2">Concepto</th>
      </tr>
    </thead>
    <tbody>
      <td>
        <?php
          if (!empty($pagos_unicos_del_ID[0]->fecha_del_deposito)) {
            print_r($pagos_unicos_del_ID[0]->fecha_del_deposito);
          } else {
            print "Sin registros";
          }
        ?>
      </td>
      <td>
        <?php
          if (!empty($pagos_unicos_del_ID[0]->importe)) {
            print_r($pagos_unicos_del_ID[0]->importe);
          } else {
            print "Sin registros";
          }
        ?>
      </td> 
      <td>
        <?php
          if (!empty($pagos_unicos_del_ID[0]->tipo_de_pago)) {
            print_r($pagos_unicos_del_ID[0]->tipo_de_pago);
          } else {
            print "Sin registros";
          }
        ?>
      </td> 
    </tbody>
  </table>
</div>

As a result:

Someone who can support me to an optimal solution for this?

Thanks in advance.

    
asked by González 10.05.2018 в 23:28
source

1 answer

1

You have to do it with on foreach loop asi:

<div class="tableFixHead">
  <table class="table table-striped">
    <thead>
      <tr>
        <th class="col-xs-2">Fecha del pago</th>
        <th class="col-xs-2">Monto</th>
        <th class="col-xs-2">Concepto</th>
      </tr>
    </thead>
    <tbody>
      <?php
        foreach($pagos_unicos_del_ID as $pago) {
            print "<tr><td>" . $pago->fecha_del_deposito . "</td><td>" . $pago->importe 
                . "</td><td>" . $pago->tipo_de_pago . "</td></tr>";
        }                      
      ?>          
    </tbody>
  </table>
</div>
    
answered by 10.05.2018 / 23:38
source