I have a general approach question, although my code is in Laravel Blade. I have data with child data. Each Parent record is represented by row, but each child data is to be displayed in the same row, just in adjacent columns. There are a set number of columns. Each parent will have varying child records. But child data needs to be displayed in particular columns.
I can't do this:
foreach($children as $data)
if(data belongs)
show content
else
show blank form
endif
endforeach
otherwise i'll have fewer td's than needed.
The best I came up with is:
<tr>
<td> Location </td>
<td>
$colA = false
@foreach($children as $data)
@if(child belongs in column A)
{{$child->content}}
@colA = true
@endif()
@end foreach
@if($colA == false)
display blank form input
@endif()
</td>
<td>
$colB = false
@foreach($children as $data)
@if(child belongs in column B)
{{$child->content}}
@colB = true
@endif()
@end foreach
@if($colB == false)
display blank form input
@endif()
</td>
//-------repeat for 6 more times
</tr>
but this seems really inefficient. Especially since i'll have up to a hundred parent records being displayed at once each with 8 "children-columns". So the foreach loop would run 800 times....
Any help at making this more efficient would be greatly appreciated.
Thank you