Default data will be add in another row even if I used else statement #laravel #bootstrap

Viewed 22

Hello everyone sorry this may be a dumb question but this situation got me stuck for 3hrs thinking what to do.

first of all this is the body for my table I use if statement so that the data from the table student and the score will coincide I'am using laravel eloquent for this project.

<tbody>
      @foreach($students as $student)
        <tr>
           <td>{{ $student->id }}</td>
           <td>{{ $student->stud_name }}</td>
               @foreach($diagnosticScores as $diagnosticScore)
                  @if($diagnosticScore->student_id == $student->id)
                    <td>{{ $diagnosticScore->score }}</td>
                  @else
                    <td>0</td>
                  @endif
                @endforeach

           <td class="text-wrap text-center" style="font-size: 12px;">
              <a href="#" id="p1" onclick="document.getElementById('userInput1').value = {{ $student->id }};" data-bs-toggle="modal" data-bs-target="#DeModal">
                <span class="badge badge-primary">
                   insert
                </span>
              </a>

this is the output for the code above the tables been altered by a value 0

And when I remove the else statement

<tbody>
          @foreach($students as $student)
            <tr>
               <td>{{ $student->id }}</td>
               <td>{{ $student->stud_name }}</td>
                   @foreach($diagnosticScores as $diagnosticScore)
                      @if($diagnosticScore->student_id == $student->id)
                        <td>{{ $diagnosticScore->score }}</td>
                      @endif
                    @endforeach
    
               <td class="text-wrap text-center" style="font-size: 12px;">
                  <a href="#" id="p1" onclick="document.getElementById('userInput1').value = {{ $student->id }};" data-bs-toggle="modal" data-bs-target="#DeModal">
                    <span class="badge badge-primary">
                       insert
                    </span>
                  </a>

this is the output

All I what Sir/Ma'am is that to put a default value in the table when the return value from table is 0 but this got me scratching my head for 3hrs.

Hoping for your considerate help Sirs/Maam thank you so much.

0 Answers
Related