Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I´m trying to display images in a laravel view with if/elseif statement but it only shows the first image

I have this table:

<tbody>
                @foreach($datosClase as $datoClase)
                  @php
                      $movimiento=($datoClase->total_calmado_movimiento/$datoClase->total_intervalos_movimiento)*100;
                      $ritmo=($datoClase->total_calmado_ritmo/$datoClase->total_intervalos_ritmo)*100;
                  @endphp

                <tr>
                    <th>{{$asignaturas[$loop->index]['name']}}</th>
                    <th>{{$periodos[$loop->index]['time']}}</th>
                    <th>{{$periodos[$loop->index]['timeFinish']}}</th>
                    <th>{{$movimiento}}</th>
                    <th>{{$ritmo}}</th>
                    <th>
                      
                      @if ( $movimiento > 90 && $ritmo > 90 )
                        <img src="{{ asset('img/cinco.png') }}" style="width:30%">
                      

                      @elseif ( $movimiento > 70 && $ritmo > 70 )
                        <img src="{{ asset('img/"cuatro.png') }}" style="width:30%">

                      @elseif ( $movimiento > 60 && $ritmo > 60 )
                        <img src="{{ asset('img/"tres.png') }}" style="width:30%">

                      @elseif ( $movimiento > 50 && $ritmo > 50 )
                        <img src="{{ asset('img/"dos.png') }}" style="width:30%">

                      @elseif ( $movimiento > 40 && $ritmo > 40 )
                        <img src="{{ asset('img/"una.png') }}" style="width:30%">

                      @else
                        <img src="{{ asset('img/"cero.png') }}" style="width:30%">
                      @endif

                    </th>
                    
                </tr>
                @endforeach
                
            </tbody>

And the problem is that it only shows the iage in the first if.
Here´s the example:
enter image description here
In the second row, as $movimiento is 75 and $ritmo is 100, and both are >70, it should display ‘img/cuatro.png’ but it doesn´t work.
I have tried using a switch instead of if/elseif but it happens still the same.
Any idea?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There are some inconsistencies with your quotes in the src attribute of the img tags.

It should be:

<img src="{{ asset('img/cuatro.png') }}" style="width:30%">

And do the same for the other img tags:

@if ( $movimiento > 90 && $ritmo > 90 )
    <img src="{{ asset('img/cinco.png') }}" style="width:30%">

@elseif ( $movimiento > 70 && $ritmo > 70 )
    <img src="{{ asset('img/cuatro.png') }}" style="width:30%">

@elseif ( $movimiento > 60 && $ritmo > 60 )
    <img src="{{ asset('img/tres.png') }}" style="width:30%">

@elseif ( $movimiento > 50 && $ritmo > 50 )
    <img src="{{ asset('img/dos.png') }}" style="width:30%">

@elseif ( $movimiento > 40 && $ritmo > 40 )
    <img src="{{ asset('img/una.png') }}" style="width:30%">

@else
    <img src="{{ asset('img/cero.png') }}" style="width:30%">
@endif

Once you’ve corrected the quotes, it should properly display the corresponding images for each condition.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading