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 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题