Create a new table if the date is not the same

2

I'm going through a foreach and the data I load into a table, but I want to load the data in different table views depending on the fecha example if the variable fecha='11-11-2017' there are 3 fields that load that data there and if the date is different that continue loading but in another table.

<table class="table table-hover">
    <thead>
        <tr>
            <th>Fecha</th>
            <th>Orden</th>

        </tr>
    </thead>
    <?php if ($seguimientos): ?>
    <?php foreach ($seguimientos as $seguimiento): ?>
    <tr>
        <td>
            <?php echo $seguimiento-> fecha; ?>
        </td>
        <td>
            <?php echo $seguimiento-> NroSolicitud; ?>
        </td>
        <td>
            <?php echo $seguimiento-> maquina; ?>
        </td>


    </tr>

    <?php endforeach; ?>
    <?php endif; ?>
</table>

Something like that, I attached a photo

I hope to have explained myself well. Greetings

    
asked by MoteCL 28.06.2018 в 19:37
source

1 answer

1

You can create an associative array using the dates as keys. Something like this:

<?php if ($seguimientos): ?>
<?php $fechas = array();
      foreach ($seguimientos as $seguimiento) {
         $fechas[$seguimiento-> fecha][] = $seguimiento;

      }
?>
<?php foreach ($fechas as $fecha): ?>
<table class="table table-hover">
<thead>
    <tr>
        <th>Fecha</th>
        <th>Orden</th>

    </tr>
</thead>
<?php   foreach ($fecha as $seguimiento): ?>
<tr>
    <td>
        <?php echo $seguimiento-> fecha; ?>
    </td>
    <td>
        <?php echo $seguimiento-> NroSolicitud; ?>
    </td>
    <td>
        <?php echo $seguimiento-> maquina; ?>
    </td>
</tr>

<?php endforeach; ?>
    </table>
<?php endforeach; ?>
<?php endif; ?>
    
answered by 28.06.2018 / 20:12
source