Show image according to variable greater or less than

3

Hello friends, let me explain, I make a query to get the scores when a user in 4 stages must acquire a number greater than 69 points, the idea is to show an image according to the score is greater or less than 69 points.

If the user does not achieve 69 points in the first stage, an image is displayed

$comp='<img src="img/icons/alert_graduate.gif" alt="">';

This same image should continue showing if even in the fourth stage this user can not get a score higher than 69 points

when the user achieves this score no matter what stage the image is displayed

$comp='<img src="img/icons/graduate.png" alt="">';

code:

if ($etapa1 > 69) {
   $comp='<img src="img/icons/graduate.png" alt="">';
} elseif ($etapa2 > $etapa1) {
    $comp='<img src="img/icons/graduate.png" alt="">';
} elseif ($etapa3 > $etapa1) {
 $comp='<img src="img/icons/graduate.png" alt="">';

} elseif ($etapa4 > $etapa1) {
$comp='<img src="img/icons/graduate.png" alt="">';

} else{

    $comp='<img src="img/icons/alert_graduate.gif" alt="">';
}
    
asked by Alexander Quiroz 28.07.2017 в 06:29
source

1 answer

1

I put two codes, one is evaluated if it is greater than or equal to 69, in another, only if it is greater than 69. If the user graduates with 69 or more points, you should use the first one, but if you graduate with 70 or more points, you should use the second.

Ver Demo del Código

   <?php

    $etapa1=69;
    $etapa2=40;
    $etapa3=30;
    $etapa4=20;


    //1ª posibilidad: Evaluando igual o  mayor a 69
    if ($etapa1 >= 69 || $etapa2 >= 69 || $etapa3 >= 69 || $etapa4 >= 69) 
    {
        $comp='<img src="img/icons/graduate.png" alt="">'; //Graduado


    } else{

        $comp='<img src="img/icons/alert_graduate.gif" alt="">'; //No graduado
    }
       echo  $comp; 


    //2ª posibilidad: Evaluando  mayor a 69


    if ($etapa1 > 69 || $etapa2 > 69 || $etapa3 > 69 || $etapa4 > 69) 
    {
        $comp='<img src="img/icons/graduate.png" alt="">'; //Graduado


    } else{

        $comp='<img src="img/icons/alert_graduate.gif" alt="">'; //No graduado
    }
       echo  "<br>".$comp; 

    ?>
    
answered by 28.07.2017 / 07:27
source