3 estates if followed with similar conditions? php

2

I can not get this headache, I need to meet a condition:

if($a == null):
    <div class="imagen1">
        <img src="http://www.juguetessomosnosotros.com/wp-content/uploads/2012/08/rubik_cubemess.png">
    </div>
endif;

if($b == null):
    <div class="imagen2">
        <img src="otra imagen">
    </div>
endif;
if($b == null and $a == null):
    <div class="imagen" style="display: none;"></div>
    <div class="imagen2" style="display: none;"></div>
endif;

But I'm still showing the first images when I want them not to show if the last condition is fulfilled.

I want if the first one is null that shows an image, that if the second one is null that shows another one, but yes, both are null at the same time that it does not show any.

    
asked by Alberto Martínez 07.06.2017 в 10:15
source

2 answers

6

Try this, you had the concatenated wrong if

<?php 
if($b == null and $a == null) {
    ?>
    <div class="imagen" style="display: none;">
        <img src="otra imagen">
    </div>
    <div class="imagen2" style="display: none;">
        <img src="otra imagen">
    </div>
    <?php
}
else {
    if($a == null) {
        ?>
        <div class="imagen1">
            <img src="http://www.juguetessomosnosotros.com/wp-
                      content/uploads/2012/08/rubik_cubemess.png">
        </div>
        <?php
    }
    if($b == null) {
        ?>
        <div class="imagen2">
            <img src="otra imagen">
        </div>
        <?php
    }
}
?>
    
answered by 07.06.2017 / 10:27
source
0

Try nesting the ifs:

<?php if($a == null) {?>

   <?php if ($b==null) {?>
      <div class="imagen">
        <img src="otra imagen" style="display: none;">
    </div>
    <div class="imagen2" style="display: none;">
        <img src="otra imagen">
    </div>
   <?php } else { ?>
     <div class="imagen1">
        <img src="http://www.juguetessomosnosotros.com/wp-
                  content/uploads/2012/08/rubik_cubemess.png">
    </div>
   <?php } ?>
<?php } else if ($b == null) {?>
   <div class="imagen2">
        <img src="otra imagen">
    </div>
<?php } ?>

So differences when both conditions are met or only one.

    
answered by 07.06.2017 в 10:26