jeudi 12 octobre 2023

How can loop and display studentId accoirding to the course_code

I want to display the students ID according to the batchId in table view. example for how I want.

EN01              EN02
12335             58965
45624             78956
46325             78599

This is my controller function.

if($request->courseId!="" && $request->batchId!="")
{
    $courseCodes = batches::where('course_id','=', $request->courseId)->where('id','=',$request->batchId)->get();
}else{
    $courseCodes = batches::where('course_id','=', $request->courseId)->get();
}


$course = courses::where('course_active','Yes')->where('course_active_flag','1')->get();
$users = User::all();

$tabliView = "";

$studentData = DB::table('students')
    ->select('studentId', 'batchId','courseId')
    ->where('courseId', $request->courseId);

if ($request->batchId != "") {
    $studentData->where('batchId', $request->batchId);
}

$studentData = $studentData->get();

And This is my table view with loop

<table class="table table-bordered text-nowrap border-bottom" id="basic-datatable">
    <thead>
        <tr>
            @foreach ($courseCode as $couscode)
                <th class="wd-15p border-bottom-0"></th>
            @endforeach
        </tr>
    </thead>
    <tbody>
        @foreach ($studentData as $student)
            <tr>
                @foreach ($courseCodes as $courseCode)
                    <td>
                        
                        @if ($student->batchId === $courseCode->id)
                            
                        @endif
                    </td>
                @endforeach
            </tr>
        @endforeach
    </tbody>
</table>

Now the result is coming like each course code same student Id is printing but each course code has a unique batchId. Please help me to fix this issue.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/H1zMqCR
via IFTTT

Aucun commentaire:

Enregistrer un commentaire