Two different conditions are valid for the same value

Asked

Viewed 56 times

-6

<td>
   <? if($online['status']==1){?>
    <span class="badge badge-primary"><?php echo lang('texto um'); ?></span>
   <?}else{?>

   <? }?>

   <?if($online['status']==2){?>
     <span class="badge badge-danger"><?php echo lang('texto dois'); ?></span>
   <? }else{?>

   <? }?>
   ...
</td>

In the table is printing both, but it was to print according to the status in the table.

What is wrong?

  • And what is the value of $online['status']? Take care of the loose comparison, she can fool you in many situations.

  • Varies from 1 and 4 . Always prints the four texts instead of only the text corresponding to the status

  • Check if the value is coming right? Give a var_dump($online) and post the result.

1 answer

-1


Try to do so. Whenever there is a new condition in "if" use "elseif":

<td>
    <?php
       if($online['status'] === 1){
    ?>
      <span class="badge badge-primary"><?php echo lang('texto um'); ?></span>
    <?php
      }elseif($online['status'] === 2){
    ?>
      <span class="badge badge-danger"><?php echo lang('texto dois'); ?></span>
    <?php
      }else{
    ?>
      etc etc etc etc continua
    <?php
     }
    ?>
</td>
  • 1

    I find it interesting that you explain why you’ve changed == for ===, because it is fundamental to understand your answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.