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条)

报告相同问题?

悬赏问题

  • ¥30 matlab appdesigner私有函数嵌套整合
  • ¥15 给我一个openharmony跑通webrtc实现视频会议的简单demo项目,sdk为12
  • ¥15 vb6.0使用jmail接收smtp邮件并另存附件到D盘
  • ¥30 vb net 使用 sendMessage 如何输入鼠标坐标
  • ¥15 关于freesurfer使用freeview可视化的问题
  • ¥100 谁能在荣耀自带系统MagicOS版本下,隐藏手机桌面图标?
  • ¥15 求SC-LIWC词典!
  • ¥20 有关esp8266连接阿里云
  • ¥15 C# 调用Bartender打印机打印
  • ¥15 我这个代码哪里有问题 acm 平台上显示错误 90%,我自己运行好像没什么问题