dougu2006 2015-05-23 06:05
浏览 32
已采纳

从另一个PHP页面更改PHP值

I'm trying to add a navbar to all the pages I have, the navbar is a PHP file, and it works for me, but I also wanna put the active navbar button, I tried my best but it didn't work...

This is my navbar.php:

<nav class="navbar navbar-default navbar-fixed-top">
<!--Brand Starts-->

<?php
$active="";
?>

<a class="navbar-brand pull-right animation-sliding-l-r" href="#">
    <img src="images/logo.png" alt="logo"/>
</a>

<!--Brand Ends-->
<button type="button" class="navbar-toggle pull-left collapsed btn navbar-btn btn-block" data-toggle="collapse"
        data-target="#navbar-collapse">
    <i class="fa fa-anchor fa-lg"></i>
</button>

<!--Navbar Buttons Start-->
<div class="collapse navbar-collapse" id="navbar-collapse">
    <ul class="nav navbar-nav">
        <li class="<?php if ($active=='Home') {echo "active";} else {  } ?>"><a href='home.php'><i class='fa fa-home fa-lg'></i> Home</a></li>
        <li class="<?php if ($active=='Store') {echo "active";} else {  } ?>"><a href='store.php'><i class='fa fa-shopping-cart fa-lg'></i> Store</a></li>
        <li class="<?php if ($active=='Report') {echo "active";} else {  } ?>"><a href='report.php'><i class='fa fa-flag fa-lg'></i> Report</a></li>
        <li class="<?php if ($active=='Moderator Application') {echo "active";} else {  } ?>"><a href='moderator-application.php'><i class='fa fa-user-plus fa-lg'></i> Mod Application</a></li>
        <li class="<?php if ($active=='About') {echo "active";} else {  } ?>"><a href='about.php'><i class='fa fa-book fa-lg'></i> About</a></li>
    </ul>
</div>
<!--Navbar Buttons End-->

and I put this in the other pages:

    <?php

    include("includes/navbar.php");
    $active = "Store";

?>

Sorry for the noob question but I searched so far but didn't find anything. Thanks in advance

  • 写回答

2条回答 默认 最新

  • dousi6701 2015-05-23 06:11
    关注

    Hello, i think you have everything good, you just need ton inverse the line ^^

    <?php
    
    
    $active = "Store";
    include("includes/navbar.php");
    
    ?>
    

    and remove

    <?php
    $active="";
    ?>
    

    on the other file

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler