Where’s the mistake I can’t see?

Asked

Viewed 44 times

4

What happens in the jeans_status and jeans_opcao it works a beauty more in the first if It doesn’t work, it goes into the if without checking whether the imagem_status == 1 and the imagem_opcao == 'galeria_imagem'. Someone might be able to explain to me what’s going on ?

<?php
            //  pd($imagens);
            foreach ($imagens as $value) {
                if (isset($value->imagem_status) == 1 and $value->imagem_opcao == "galeria_imagem") {
                    ?>
                    <div class="portfolio-item col-md-3 code">

                        <figure>
                            <a class="example-image-link" href="<?php echo base_url('tema/assets/img/site/' . $value->imagem_link); ?>" data-lightbox="example-set" data-title="<?php echo $value->imagem_descricao ?>">
                                <div class="image-hover">
                                    <img width="200px" height="200px" src="<?php echo base_url('tema/assets/img/site/' . $value->imagem_link); ?>" alt="<?php echo $value->imagem_titulo ?>">
                                    <h5 class="margin-top-20"><?php echo $value->imagem_titulo ?></h5>
                                </div>
                            </a>
                            <div class="overlay">

                            </div>
                        </figure>




                        <div class="clearfix"></div>
                    </div>

                <?php } elseif ($value->jeans_status == 1 and $value->jeans_opcao == "galeria_jeans") { ?>
                    <div class="portfolio-item col-md-3 code">



                        <figure>
                            <a class="example-image-link" href="<?php echo base_url('tema/assets/img/jeans/' . $value->jeans_link); ?>" data-lightbox="example-set" data-title="<?php echo $value->jeans_descricao ?>">
                                <div class="image-hover">
                                    <img width="200px" height="200px" src="<?php echo base_url('tema/assets/img/jeans/' . $value->jeans_link); ?>" alt="<?php echo $value->jeans_titulo ?>">
                                    <h5 class="margin-top-20"><?php echo $value->jeans_titulo ?></h5>
                                </div>
                            </a>
                            <div class="overlay">
                            </div>
                        </figure>




                        <div class="clearfix"></div>

                    </div>
                    <?php
                }
            }
            ?>
  • you’re not checking out if imagem_status is equal to 1 you are checking whether the isset() is 1 (true)

1 answer

4


The current check compares if the result is isset() is true and if imagem_opcao is galeria_imagem. I also suggest you change the and for && since they are not equal, have different priorities.

Change:

isset($value->imagem_status) == 1 and $value->imagem_opcao == "galeria_imagem"

To:

isset($value->imagem_status) && $value->imagem_status == 1 && $value->imagem_opcao == "galeria_imagem"

Recommended reading:

Qual a diferença entre “&&” e “||” e “and” e “or” em PHP? Qual usar?

  • Perfect friend. More look there, I did not know that the isset already entered the parole

Browser other questions tagged

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