Hi all i’m a bit stuck and need some help.
I have a query which returns the following
Array
(
[0] => stdClass Object
(
[id] => 1
[username] => Joe Blogs
[user_number] => JB222
[email] => jb@kemail.com
[job_title] => Teacher
[contractor] => Direct Hire
[campus] => Male Humanities
[role] => Teacher
[section_number] => 11111 | 213312 | 232121 | 432231
[stid] => 89,91,95,94
[classroom] => 2621,1329,1428,3123
[subject] => English | Physics | English | Maths
)
)
I need to be able to break this apart so i can loop through the stid,section,classroom and subjects as part of a nested loop.
Id like to join the section and classroom together and keep the stid separate so i can use it in a link. I also want to keep the class separate.
-----------------------------------------------
| sections | classroom | Teacher |
-----------------------------------------------
this would be a link with stid 89 -> | English 11111 | 2621 | Joe Blogs |
this would be a link with stid 91 -> | Physics 213312 | 1329 | |
| English 232121 | 1428 | |
| Maths 432231 | 3123 | |
-----------------------------------------------
I’ve tried different things and can’t get them to work. Below is what i tried but i could work out how to get each stid as a value in the link. I also tried to to put an if statement to say N/A if the class was empty but that wasn’t working either.
OLD CODE
<ul>
@if ( empty($teacher->subject) )
N/A
@else
<?php
$sections = explode(' | ',$teacher->section_number );
$subjects = explode(' | ',$teacher->subject);
$data = array_combine($sections,$subjects); ?>
@foreach ( $data as $section=>$class)
<li>{{ $section . " - " .$class }}</li>
@endforeach
@endif
</ul>
</td>
<td>
<ul>
<?php $classrooms = explode(',',$teacher->classroom); ?>
@foreach ( $classrooms as $room)
<li>{{ $room }}</li>
@endforeach
</ul>
Any help would be appreciated. especially with some explanation as to where i went wrong.
Thanks
1 Answer