dounao5856 2015-05-22 18:04
浏览 20
已采纳

如何使用PHP隐藏<Div>

Hi I have used some code but I want it so when the name is NULL it is hidden, if this is possible please help.

Here is the code

    <p id="top"><strong>Welcome back <?php echo $_SESSION['name']; ?> [<a href="admin/logout.php">Logout</a>]<br/>Welcome To the homepage of The Journalist's</p>

I want it to be when name is NULL, for

    "<strong>Welcome back <?php echo $_SESSION['name']; ?> [<a href="admin/logout.php">Logout</a>]" 

to be hidden.

Thank you.

update... This is what i have so far This is what i have so far.

    <?php
    if ($SESSION['name']= NULL) {
    ?>
    <div><strong>Welcome back <?php echo $_SESSION['name']; ?> [<a  href="admin/logout.php">Logout</a>]</div>
    <?php
    }
    ?>

I have fixed it , thank you for everyone that has commented. for anyone else with this problem. here is my solution.

    <?php
    if ($_SESSION['name']!= NULL) {
    ?>
    <strong>Welcome back <?php echo $_SESSION['name']; ?> [<a href="admin/logout.php">Logout</a>]<br/>
    <?php
    }
    ?>
  • 写回答

1条回答 默认 最新

  • douchuang8359 2015-05-22 18:05
    关注

    Update from your posted code:

    For one, you are using $SESSION instead of $_SESSION. Second, you are setting $SESSION['name'] using a single equal sign, so the if condition would always fail because it is evaluating if (NULL). You need to use == or ===. Read up on comparison operators.


    <?php
    if (condition) {
    ?>
    <div></div>
    <?php
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭