display data in a table [closed]

0

How do I not see the one available in the column that is already not available, if I do it with @else it's worse since I go through the array 3 times.

<table>
  <thead>
    <tr>
      <th>Hora</th>
      <th>Fecha</th>
      <th>Paciente</th>
      <th>Status</th>
    </tr>
  </thead>
  <tbody>
    @foreach($a as $x)
    <tr>
      <td>{{$x}}</td>
      @foreach($b as $z) @if($x == $z)
      <td>14:00</td>
      <td>Lopez</td>
      <td>no disponible</td>
      @endif @endfor
      <td></td>
      <td></td>
      <td>disponible</td>
    </tr>
    @endforeach

  </tbody>
</table>

Result:

Hora    Fecha   Paciente    Status
10          disponible
12          disponible
13  14:00   Lopez   no disponible           disponible
14  14:00   Lopez   no disponible           disponible
15          disponible
16          disponible
17          disponible
18  14:00   Lopez   no disponible           disponible
19          disponible
20          disponible
    
asked by Segurida IT 08.11.2017 в 20:36
source

2 answers

1

seems to be laravel's blade (templates), and that you've messed with the if else try this:

<table>
  <thead>
    <tr>
      <th>Hora</th>
      <th>Fecha</th>
      <th>Paciente</th>
      <th>Status</th>
    </tr>
  </thead>
  <tbody>
    @foreach($a as $x)
{{-- por cada linea --}}
    <tr>
      <td>{{$x}}</td>
{{-- mostramos x en primer columna --}}

      @foreach($b as $z) 
{{-- por cada columna extra --}}
      @if($x == $z)
{{-- si x=z mostramos columnas paciente --}}
      <td>14:00</td>
      <td>Lopez</td>
      <td>no disponible</td>

      @else
{{-- de lo contrario mostramos columnas vacias + disponible --}}
      <td></td>
      <td></td>
      <td>disponible</td>
      @endif 
{{-- fin si x=z --}}
    @endfor
{{-- fin por cada columna extra --}}
    </tr>
    @endforeach
{{-- fin por cada linea --}}
  </tbody>
</table>
    
answered by 30.03.2018 в 06:34
0

I think you mean a else

   <table>
  <thead>
    <tr>
      <th>Hora</th>
      <th>Fecha</th>
      <th>Paciente</th>
      <th>Status</th>
    </tr>
  </thead>
  <tbody>
    @foreach($a as $x)
    <tr>
      <td>{{$x}}</td>
      @foreach($b as $z) 
      @if($x == $z)
      <td>14:00</td>
      <td>Lopez</td>
      <td>no disponible</td>
      @else
      <td></td>
      <td></td>
      <td>disponible</td>
      @endif
      @endforeach
    </tr>
    @endforeach

  </tbody>
</table>

Also remember to close your foreach with @endforeach

    
answered by 30.03.2018 в 06:33