I table student_atendence table fields are (id ,studid,attendence).
This is my table student_atendence:
studid attendence
28 1
31 1
32 1
28 1
31 1
32 1
28 1
31 1
32 1
28 1
31 0
32 1
28 0
31 1
32 1
28 1
31 1
32 0
28 1
31 1
32 0
I want result like this
id studid total 1's total 0's
1 28 6 1
2 31 6 1
3 32 5 2
How can I get the total count of attendence =1 and attendence=0 of each students separately?
Eg: 28 - 6 (total no.of 1 s) and 1(total o.of 0 s), 31 - 6 (total no.of 1 s) and 1(total o.of 0 s), 32 - 5 (total no.of 1 s) and 2(total o.of 0 s).
My controller code :
foreach($students as $student){
$cunt1 = DB::table($wys_attendence_table)
->where('studid',$student->id)
->where('amonth',$amonth)
->where('ayear',$ayear)
->where('attendence','=',1)
->count();
$cunt0 = DB::table($wys_attendence_table)
->where('studid',$student->id)
->where('amonth',$amonth)
->where('ayear',$ayear)
->where('attendence','=',0)
->count();
//var_dump($cunt1);
//var_dump($cunt0);
}
My view page:
@foreach($stud_attend as $stud_attends)
@if($student->id == $stud_attends->studid)
@if($stud_attends->attendence == 1)
<td>
<font color="green" size="3">p</font>
</td>
@elseif($stud_attends->attendence == 0)
<td>
<font color="red" size="3">a</font>
</td>
@endif
<td>{{ $cunt1 }}</td>
<td>{{ $cunt0 }}</td>
@endif
@endforeach
I get the correct answer from var_dump($cunt0), var_dump($cunt1) but it does not work in the view page.