this is my output in the form of an array
[0] => stdClass Object
(
[status] => P
October 14, 2022 => 10/02/2022
[firstname] => testing 10
[subject_id] => 5
)
[1] => stdClass Object
(
[status] => A
October 14, 2022 => 10/02/2022
[firstname] => arsalan 12
[subject_id] => 5
)
[2] => stdClass Object
(
[status] => L
October 14, 2022 => 10/02/2022
[firstname] => khan 4
[subject_id] => 5
)
[3] => stdClass Object
(
[status] => P
October 14, 2022 => 10/03/2022
[firstname] => testing 10
[subject_id] => 5
)
[4] => stdClass Object
(
[status] => L
October 14, 2022 => 10/03/2022
[firstname] => arsalan 12
[subject_id] => 5
)
[5] => stdClass Object
(
[status] => A
October 14, 2022 => 10/03/2022
[firstname] => khan 4
[subject_id] => 5
)
[6] => stdClass Object
(
[status] => P
October 14, 2022 => 10/04/2022
[firstname] => testing 10
[subject_id] => 5
)
[7] => stdClass Object
(
[status] => P
October 14, 2022 => 10/04/2022
[firstname] => arsalan 12
[subject_id] => 5
)
[8] => stdClass Object
(
[status] => P
October 14, 2022 => 10/04/2022
[firstname] => khan 4
[subject_id] => 5
)
[9] => stdClass Object
(
[status] => P
October 14, 2022 => 10/05/2022
[firstname] => testing 10
[subject_id] => 5
)
[10] => stdClass Object
(
[status] => A
October 14, 2022 => 10/05/2022
[firstname] => arsalan 12
[subject_id] => 5
)
this is the code on the controller
$attendance = DB::table('attendances')
->join('users', 'attendances.user_id', '=', 'users.id')
->havingBetween('attendances.date', array($dateFrom, $dateTo))
->having('attendances.subject_id','=',$ideas[0])
->orderBy('attendances.date','asc')
->get(['attendances.status','attendances.date','users.firstname','attendances.subject_id'])->toArray();
I want this type of array
[0] => stdClass Object
(
[status] =>
[
P,
p,
p,
p
]
October 14, 2022 => [
10/02/2022,
10/03/2022,
10/04/2022,
10/05/2022,
]
[firstname] => testing 10
[subject_id] => 5
)
[1] => stdClass Object
(
[status] =>
[
A,
L,
p,
A
]
October 14, 2022 => [
10/02/2022,
10/03/2022,
10/04/2022,
10/05/2022,
]
[firstname] => arsalan 12
[subject_id] => 5
)
[2] => stdClass Object
(
[status] =>
[
L,
a,
p,
A
]
October 14, 2022 => [
10/02/2022,
10/03/2022,
10/04/2022,
10/05/2022,
]
[firstname] => khan 4
[subject_id] => 5
)
to show students’ attendance on the table form, just like attendance registered.
attendance not on daily bases.
please help me I have no idea what to do about this. this is my second question on the same problem.
2
Answers
with small changes, it works for me such as
the output is
You want to group by
firstname
. We’ll just loop over the items adding to the array of an item with the key offirstname
as we go.Output: