Load data in specific columns

-2

I have a collection that brings me data from the station table, equipment table related to that station and the parameters that each team can measure. This is obtained through the relationships in the models.

 Estacion
 Equipo 
 Equipo_estacion
 Parametro
 Equipo_Parametro

I get a collection with the data Station> Team> parameter

in the controller I pass an ordered arrangement with the position and name of the parameters, this I compare with those obtained from the base

$param_header = array('MP10','MP25','SO2','NO2','CO','O3','BC');   

and I want to load in the table every field where a station has a device that measures that parameter

the first data of the row loads it in the correct position, that is, in the station Bodega1, there is a device that measures the SO2 parameter and another that measures NO2, in the image NO2 it does not correspond with its corresponding column and the same thing it happens in some of the following rows.

  @foreach($est_equi as $item1)
           @foreach($item1->equipos as $equipo)

          <tr> 

            <td>{{ $item1->region_id }} </td>
            <td>{{ $item1->nombre .'-' . $item1->id   }} </td>

            @foreach($equipo->parametros as $key=>$param)
               @php ($i = 0) 

               //Aca comprueba en que posicion dentro del arreglo esta el parametro

              {!! $posicion = array_search($param->nombre, $param_header) !!}
                 {{ 'Las posicion es :' .$offset }}</br> 

                  @while ($i < 7)

                    @if($i == $posicion)
                        <td>{{ $param->nombre}} </td>
                        @break;
                    @else
                        <td> no </td>
                    @endif   
                  @php ( $i++ )     

                  @endwhile       
            @endforeach

          </tr> 
    
asked by Rodrigo Rose 26.04.2017 в 16:33
source

1 answer

-1

You do not specify too much, but I do not know why life is so complicated, simply set the parameter in the column that corresponds to something like:

<tr> 
    @foreach($equipo->parametros as $key=>$param)
        // COLUMNA 1
        <td>{{ $param->parametro_1 }}</td>
        // COLUMNA 2
        <td>{{ $param->parametro_2 }}</td>
        // COLUMNA 3
        <td>{{ $param->parametro_3 }}</td>
        // COLUMNA 4
        <td>{{ $param->parametro_4 }}</td>
        // COLUMNA 5
        <td>{{ $param->parametro_5 }}</td>

        // COLUMNA N
        <td>{{ $param->parametro_N }}</td>
    @endforeach
</tr> 
    
answered by 26.04.2017 в 18:05