I want to show a table in html of a query of the database of three tables that are related, the tables are structured as follows:
Restaurant | Platos | Precios
-----------------------------------------
id | id | id
nombre | nombre | restaurant_id
| descripcion | plato_id
| | precio
Where the table I want to show is structured as follows:
platos | restaurant 1 | restaurant 2 | restaurant 3 |
------------------------------------------------------
plato 1 | 10 | X o 0 | 15 |
plato 2 | X o 0 | 5,4 | 7 |
plato 3 | X o 0 | 12 | X o 0 |
plato 4 | 10 | 11,5 | 17 |
plato 5 | 6 | 6,5 | 10 |
where X or O appears is when that restaurant has no price for that dish or that record does not exist.
I have tried but I do not get the table that way, if someone has already done it or has a serious idea of great help. Thanks
The project is written with the laravel framework, the variables used have been these:
I get an arrangement with all the dishes $ dishes
I get an arrangement with all the restaurant $ restaurant
and I get an arrangement of the prices $ prices
the html code is:
<table>
<thead>
<tr>
<th>Platos</th>
@foreach($restaurant as $res)
<th>{{$res->nombre}}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach($platos as $pla)
<tr>
<td>{{$pla->nombre}}</td>
@foreach($restaurant as $res)
@foreach($precios as $pre)
@if($pre->restaurant_id==$res->id && $pre->plato_id==$pla->id)
<td>{{$pre->precio}}</td>
@else
<td>0</td>
@endif
@endforach
@endforach
</tr>
@endforeach
</tbody>
</table>
That's the code used, but it does not work, it does not show the prices in the order that corresponds to each restaurant