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 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献