dongliuzi3410 2013-05-14 13:37
浏览 32
已采纳

加载 - >根据SQL字段查看文件

I'm trying to load a file (a website header) depending on a preference set by a user, which is stored in a mysql db field.

This code loads the header when placed on any page:

<?php $this->load->view('header');?>

Users have an option to select/deselect the header in the preferences. to show the header the term 'show' is saved to the cell in the database and 'hide' to hide.

I have been working this code:

<?php if(($boardDetails->showheader)):show ?>
<?php $this->load->view('header');?>
<?php endif ?>

Where 'showheader' is the database field name and 'show' is the content within it. But I keep getting errors with conflicting php code in the same file: unexpected end etc. When I trim them up to make it viewable the header is loaded regardless of the content of the users field. So 'show' and 'hide' both display the header.

Does anyone have a simpler way of selecting this option working with my current code?

  • 写回答

1条回答 默认 最新

  • dscrn1974 2013-05-14 14:10
    关注

    Your should try something like this:

        <?php 
             if(($boardDetails->showheader)=="show"){
              $this->load->view('header');
              } 
    
        ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?