intothefray2007 Posted September 14, 2008 Share Posted September 14, 2008 Someone gave me a hand with a way to load breadcrumbs after the header has loaded, but I'm having trouble getting this to work. Can anyone take a look? I'm using the following structure: ---------------------- index.php ---------------------- <?php include_once('includes/header.php'); ?> <?php include_once('includes/menu.php'); ?> <?php include_once('includes/side.php'); ?> <?php if (isset($_GET['pg']) && $_GET['pg'] != "") { $pg = $_GET['pg']; if (file_exists('pages/'.$pg.'.php')) { @include ('pages/'.$pg.'.php'); } elseif (!file_exists('pages/'.$pg.'.php')) { echo 'The page you requested does not exist'; } } else { @include ('pages/home.php'); } ?> <?php include_once('includes/footer.php'); ?> ---------------------- menu.php ---------------------- <?php $breadcrumb = array('home'=>'Home', 'about'=>'About Us'); if(isset($_GET['pg'])){ if(array_key_exists($_GET['pg'], $breadcrumb)){ echo $breadcrumb[$pg]; } else{ echo 'This breadcrumb does not exist'; } } else{ echo $breadcrumb['home']; } ?> ------------------------------------------------------------------------------- A sample URL would be http://www.mywebsite.com/?pg=about The original script in the index.php file checks the variable $pg and includes the appropriate PHP file from the /pages directory. The breadcrumb script in menu.php also checks the $pg variable and sets the breadcrumb accordingly. Sounds good.... but for some reason it is not printing out anything at all ($breadcrumb), UNLESS I load the URL without a ?pg= value, in which case I get the default value ('home'). Anyone have any ideas? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/124238-script-not-working/ Share on other sites More sharing options...
Adam Posted September 14, 2008 Share Posted September 14, 2008 Okay firstly, just as a heads up you don't need... <?php include_once('includes/header.php'); ?> <?php include_once('includes/menu.php'); ?> <?php include_once('includes/side.php'); ?> <?php if (isset($....... you can just use... <?php include_once('includes/header.php'); include_once('includes/menu.php'); include_once('includes/side.php'); if (isset($........... ------------- Try adding some static text to the echo to see if it it's something to do with setting up the array.. like... if(array_key_exists($_GET['pg'], $breadcrumb)){ echo 'Breadcrumbs: ' . $breadcrumb[$pg]; } else{ echo 'This breadcrumb does not exist'; } Adam Quote Link to comment https://forums.phpfreaks.com/topic/124238-script-not-working/#findComment-641566 Share on other sites More sharing options...
intothefray2007 Posted September 15, 2008 Author Share Posted September 15, 2008 Good suggestion, it did output the text so there is obviously something wrong with the array's output... but why? Quote Link to comment https://forums.phpfreaks.com/topic/124238-script-not-working/#findComment-641608 Share on other sites More sharing options...
intothefray2007 Posted September 15, 2008 Author Share Posted September 15, 2008 Turned on error reporting and got the following: Notice: Undefined variable: pg in /home/blackbir/public_html/test/v3/includes/menu.php on line 47 Notice: Undefined index: in /home/blackbir/public_html/test/v3/includes/menu.php on line 47 Not quite sure how to deal with that...? Quote Link to comment https://forums.phpfreaks.com/topic/124238-script-not-working/#findComment-641986 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.