dsjq62428 2017-10-02 13:11
浏览 48
已采纳

CodeIgniter 3:if语句在Php中不起作用的多个条件

I'm new with CodeIgniter. I have an if/if else statement in my view file and the codition after || is not working

Here's a code from my view

<?php if (($destination["site"]!="block_view/profile/profile")||($destination["site"]!="block_view/profile/slips")){
?>


<section id="profilephp-header" style="background-image: url(<?php echo base_url('assets/img/parallax/header-profile.jpg'); ?>);" class="parallax">
    <div class="overlay">
        <div class="container">
            <div class="row">
                <div class="sec-title text-center wow animated fadeInDown">
                    <img src="<?php echo base_url('assets/img/parallax/profile-text.png'); ?>" alt="">
                </div>
            </div>
        </div>
    </div>
</section>
<?php 
}else if(($destination["site"]=="block_view/profile/profile")||($destination["site"]=="block_view/profile/slips")){?>
    <section id="profilephp-header2" style="background-image: url(<?php echo base_url('assets/img/parallax/header-profile.jpg'); ?>);" class="parallax">
        <div class="overlay">

        </div>
    </section>
<?php
}?>

It seems like the if statement is only accepting one condition. All the conditions in my view files is like this.

  • 写回答

3条回答 默认 最新

  • doujiu8178 2017-10-02 13:19
    关注

    $destination['site'] has one value, but in your first if-statement, you're checking if it's either not equal to one thing, or it's not equal to another thing. That'll always be true!

    It looks like you were intending to show that section if the destination site was neither of those, so you could rewrite it as this:

    <?php if (!in_array($destination['site'], ['block_view/profile/profile', 'block_view/profile/slips'])): ?>
    <section id="profilephp-header" style="background-image: url(<?php echo base_url('assets/img/parallax/header-profile.jpg'); ?>);" class="parallax">
        <div class="overlay">
            <div class="container">
                <div class="row">
                    <div class="sec-title text-center wow animated fadeInDown">
                        <img src="<?php echo base_url('assets/img/parallax/profile-text.png'); ?>" alt="">
                    </div>
                </div>
            </div>
        </div>
    </section>
    <?php else: ?>
        <section id="profilephp-header2" style="background-image: url(<?php echo base_url('assets/img/parallax/header-profile.jpg'); ?>);" class="parallax">
            <div class="overlay">
    
            </div>
        </section>
    <?php endif; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?