PHP nav code not changing folders.

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

I have a piece of PHP code used on my homesite that I use for the navigation. I have a random section featureing random "intelligence" but since there are so many pages, I have put it into a seperate folder named "intel" where the rest of the site is found in the folder "content".

Here is the PHP I'm haing problems with:

<?php
  $nav_array
= array(
      \
"home~Home~Impulsive Knowledge Home~content\",
      \"links~Links~Links~content\",
      \"code~Code~Misc Code~content\",
      \"phpcode~PHP Code~PHP Code~content\",
      \"rights~Rights~Your Rights~content\",
      \"jokes~Jokes~Random Jokes~content\",
      \"css_tips~CSS Tips~Some tips with CSS~content\",
      \"intelligence~Intelligence~Random Intelligence~intel\",
      //\"downloads~Downloads~Downloads~content\",
      \"ascii~ASCII~ASCII Codes~content\",
      \"aboutme~About Me~A bit about me~content\",
      \"contact~Contact Me~Contact Me~content\",
      \"disclaimer~Disclaimer~Disclaimer~content\",
    );
 
  foreach(
$nav_array as $key => $string)
    {
     
$detail = explode(\"~\", $string);
      echo
$detail[3] . \", \";
      if(trim(strtolower(
$detail[0])) == trim(strtolower($page)))
        {
         
$nav_content .= \"<a href=\\"index.php?page=\" . $detail[0] . \"\\" class=\\"link-nav-current\\" title=\\"\" . $detail[1] . \"\\">\" . $detail[1] . \"</a>\n\";
         
$page_title = $detail[1];
         
$page_h1 = $detail[2];
         
$page_folder = \"./\" . $detail[3] . \"/\";
          //echo
$detail[3];
          echo
$page_folder;
        }
      else
        {
         
$nav_content .= \"<a href=\\"index.php?page=\" . $detail[0] . \"\\" class=\\"link-nav\\" title=\\"\" . $detail[1] . \"\\">\" . $detail[1] . \"</a>\n\";
        }
    }
?>

Anyone know why?

..incase anyone is curious, I'm giving my site a total make over.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

dude, you can't have comments in the middle of an array, can you?!

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

Well, to be quite honest I've had them there for quite a while and it hasn't been effecting it in any way (I think). Not sure if it does matter or not :S

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

k, that's interesting, lol. I guess because it's over multiple lines. Hmmm...

Anyway, what problem are you having in specific?

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

I have a random section featureing random "intelligence" but since there are so many pages, I have put it into a seperate folder named "intel" where the rest of the site is found in the folder "content". PHP is not changing the folder reference. i.e. from "content" to "intel" and vice versa.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

I just spent 10 minutes reading this and your code and finally I see what you mean.

the last item in your array is the folder.

So! The thing to do (I'm really tired, bear with me) is to see if the right folder information is being returned from the array --

<?php
foreach($nav_array as $key => $string) {
___$detail = explode(\"~\", $string);
___echo
$detail[3];
    exit;
}
?>

I prefer a database for all this information, but that's probably just me.

What's it look like? Can I see a sample page?

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

I can't use a database :S

You can see what I've done so far at:
http://chengeu.krayup.com/new/index.php
And if you're curious to see how my log file thingy turned out it can be found here:
http://chengeu.krayup.com/new/log.php
Smiling

The folder that it points to is up the top. That what you wanted to see? Notice how it points to "./content/" when you click on the "intelligence" link?

I think a .phps file might be of some help here.
http://chengeu.krayup.com/new/data.phps

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

I can't do this today, if it's not resolved I'll check in Tuesday (Thanksgiving here) -- however, I'd *highly* recommend that you comment the hell out of your source. Explicitly state what each piece does. Not only will it help others help you, it will help you identify problem areas.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

<?php
$page_ext
= \".php\";

$nav_array = array(
            'home'          => array('title' => 'Home', 'h1' => 'Impulsive Knowledge Home', 'folder' => 'content'),
            'links'         => array('title' => 'Links', 'h1' => 'Links', 'folder' => 'content'),
            'code'          => array('title' => 'Code', 'h1' => 'Misc Code', 'folder' => 'content'),
            'phpcode'       => array('title' => 'PHP Code', 'h1' => 'PHP Code', 'folder' => 'content'),
            'rights'        => array('title' => 'Rights', 'h1' => 'Your Rights', 'folder' => 'content'),
            'jokes'         => array('title' => 'Jokes', 'h1' => 'Random Jokes', 'folder' => 'content'),
            'css_tips'      => array('title' => 'CSS Tips', 'h1' => 'Some tips with CSS', 'folder' => 'content'),
            'intelligence'  => array('title' => 'Intelligence', 'h1' => 'Random Intelligence', 'folder' => 'intel'),
            //'downloads'     => array('title' => 'Downloads', 'h1' => 'Downloads', 'folder' => 'content'),
            'ascii'         => array('title' => 'ASCII', 'h1' => 'ASCII Codes', 'folder' => 'content'),
            'contact'       => array('title' => 'About Me', 'h1' => 'A bit about me', 'folder' => 'content'),
            'ascii'         => array('title' => 'Contact Me', 'h1' => 'Contact Me', 'folder' => 'content'),
            'disclaimer'    => array('title' => 'Disclaimer Me', 'h1' => 'Disclaimer', 'folder' => 'content')
            );



$page_folder = !isset($page_folder) ? \"./content/\" : strtolower(trim($page_folder));

if (!isset(
$page) || !file_exists($nav_array[$page]['folder'] . $page . $page_ext)) {
   
$page = 'home';
}

$page_folder = $nav_array['home']['folder'];
$page_title = $nav_array['home']['title'];
$page_h1 = $nav_array['home']['h1'];

foreach(
$nav_array as $key => $string) {
    if(trim(strtolower(
$key)) == trim(strtolower($page))) {
       
$nav_content .= \"<a href=\\"index.php?page=\" . $key . \"\\" class=\\"link-nav-current\\" title=\\"\" . $string['title'] . \"\\">\" . $string['title'] . \"</a>\n\";
    }
    else {
       
$nav_content .= \"<a href=\\"index.php?page=\" . $key . \"\\" class=\\"link-nav\\" title=\\"\" . $string['title'] . \"\\">\" . $string['title'] . \"</a>\n\";
    }
}

if file_exists(
$page_folder . \"tips.php\") include($page_folder . \"tips.php\");

if file_exists(
$page_folder . \"insults.php\") include($page_folder . \"insults.php\");

$file = !isset($file) ? \"./logs/log\" . date(\"nY\") . \".txt\" : trim(strtolower($file));
$file = !file_exists($file) ? \"./logs/log\" . date(\"nY\") . \".txt\" : trim(strtolower($file));
?>
I don't see where you actually included the pages.

Mark Hensler
If there is no answer on Google, then there is no question.

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

I include data.php and the content page ($page) in the index.php file.

I think I'll include the .phps file soon, I think the one up now is not up to date.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.