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

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路