php - $_GET does not work in some areas of the page -


so page has lot of include calls on different parts of page. of these includes have kind of function grabs $_get variables. of them work fine, except navigation file doesn't return when try grab variables.

nav.php

<? require_once("config.php"); require_once("functions.php"); ?>  <div id="nav">      <ul>          <? initializemainnav( $_get['page'] ); ?>      </ul>  </div> 

inside function.php

function initializemainnav( $curpage ) {      // array ( slug, name ) of navigation items      $nav = array(         array( "", "home" ),         array( "case_studies", "investment case studies" ),         array( "current_inv", "current investments" ),         array( "about", "about mdig" ),         array( "management", "management" ),         array( "news", "news" ),         array( "services", "services" ) );      // print out each nav item, , highlight current page nav item      for( $i = 0; $i < count( $nav ); $i++ ) {          echo "  <li><a ";          if( $nav[$i][0] == $curpage )             echo "class=\"active\" ";          echo "  href=\"?page=" . $nav[$i][0] . "\">" . $nav[$i][1] . "</a></li> ";      }  } 

$_get['page'] returns empty, tho works on other parts of page. guys see i'm doing wrong?

edit:

index.php header constant var defines path, located in config.php

<? require_once("config.php"); require_once("functions.php"); ?>   <? include(header); ?>  <body>      <div id="wrapper">          <div id="logo">              <a href="<? echo domain; ?>"><img src="<? echo images; ?>/logo.png" alt="<? echo company; ?>"></a>         </div>          <div class="clear"></div>           <? include(nav); ?>           <div id="content_wrapper">              <!-- find , display appropriate page -->             <? displaypage( $_get['page'] ); ?>          </div>          <div class="clear"></div>           <? include(footer); ?>      </div>  </body> </html> 

i know doesn't give answer why isn't working, how following:

functions.php

function echomainnav($curpage) {    echo '<div id="nav"><ul>';    echo initializemainnav( $curpage );    echo '</ul></div>'; } 

somepage.php

<? require_once("config.php"); require_once("functions.php"); ?>   <? include(header); ?>  <body>      <div id="wrapper">          <div id="logo">              <a href="<? echo domain; ?>"><img src="<? echo images; ?>/logo.png" alt="<? echo company; ?>"></a>         </div>          <div class="clear"></div>           <? echomainnav( $_get['page'] ); ?>           <div id="content_wrapper">              <!-- find , display appropriate page -->             <? displaypage( $_get['page'] ); ?>          </div>          <div class="clear"></div>           <? include(footer); ?>      </div>  </body> </html> 

or better yet:

templates.php

define('templates_main_nav', '<div id="nav"><ul>%s</ul></div>'); 

functions.php

function getmainnav($curpage) {    return sprintf(templates_main_nav, initializemainnav( $curpage ) ); } 

somepage.php

<?= getmainnav($_get['page']); ?> 

Comments

Popular posts from this blog

All overlapping substrings matching a java regex -

c++ - Using OpenSSL in a multi-threaded application -

php - Deleting/Renaming a locked file -