Oct 1, 2021
0
Level 5
Issue in looping over main foreach and innerforeach in <table>
guys iam working with a school project.
My expected output
name Maths english science social total
AA 90 80 50 60 280
BB 80 100 100 80 360
.
.
My code
<table>
<thead>
<tr>
<th>S.No</th>
<th> Name</th>
// this foreach for <thead> to print the subject names
@foreach($subject_list->unique('subject_id') as $list)
<th>{{ $list->subject_name }}</th>
@endforeach
<th>Total</th>
<th>%</th>
</tr>
</thead>
<tbody>
@foreach ($students as $index=>$student)
// this main loop brings the first student inside
@foreach($student->studentexamsubjectwisemark as $printmark)
// this inner loop brings first student 5 subject marks
@endforeach
<tr>
<td> {{ $student->name_of_the_studeent }} </td>
<td> {{ $student->his_first_subject_mark }} </td>
<td> {{ $student->his_second_subject_mark }} </td>
<td> {{ $student->his_third_subject_mark }} </td>
<td> {{ $student->his_fourth_subject_mark }} </td>
<td> {{ $student->his_fifth_subject_mark }} </td>
</td>
@endforeach
<tbody>
</table>
actually i need to print each student name and marks. here the subjects are dynamic based on subject selected the report is generated. it may 2 subjects, 2 or 4 and so on. thats why i put a foreach in thead also
in tbody the first foeach first student will come he may wrote only 2 exams remaining 3 exams he may be absent. so my doubt is
- if i print the marks after the innerforeach iam unable to print . if i print the marks with student name within the innerforeach the it will be correct but student name will be printed as much as subject count. so how i need to print the student mark as innerforeach contain the suject.
2)if student absent means there will be no record then how i shud compare and print 0 if student not has record.
Kindly some one help please.
Please or to participate in this conversation.