PHP4 menu script problems..
Posted: Mon Apr 28, 2003 5:28 am
Ok, first off I know very very little about PHP, I'm still in the learning stages. I'm currently building a site that is using a CSS navigation menu, but I want it to be dynamic to whatever page you're on. I'm also using a template system for the site, so the area that the below script is in is in the header include file.
I had a friend who helped me out a little bit but he's left town on vacation and didn't tell me till just now, so I'm in a bind because I needed this site done two weeks ago.
Here's what I'm trying to do: You load up the page and it goes through the following code to post the navigation links. It will set a $whatpage variable so it can check that and if it's on the page that the variable is set too, that navigation link will be turned off and highlighted through CSS.
The $pages variable is the info that gets plugged into the end of the URL to set the $whatpage variable. I have 2 problems with the current script.
1) Instead of listing the actual names from the $navnames variable, it's simply putting "Array" in every link name.
2) The $whatpage variable isn't getting reset when you click on a link, so the same link button remains highlighted no matter where you go in the site. I was under the assumption that by putting it at the end of the URL for whatever page you're on. "IE: blah.com?whatpage=thepageyoureon" would reset the $whatpage variable each time, am I wrong on that? I think the problem with this is that because this script is in the header file, it keeps resetting the variable to "news", so it's ignoring the other info. Should I include the variable reset in the actual page where the content is instead?
Anyway, if anyone can help me out with this, I would REALLY appreciate it. I need to get this site up and running but this is the main thing holding me back.
Thanks for your help!!!!
Esch
<?php
$pages = array("news", "aboutthestaff", "directorratings", "forum", "contests", "submissions", "links", "contact");
$navnames = array("News", "About The Staff", "Director Ratings", "Forum", "Contests", "Submissions", "Links", "Contact");
$whatpage = "news";
$display = "";
foreach ($pages as $page){
if ($whatpage != $page)
$display .= "<div id='leftnav'><a href='{$page}.php?whatpage={$page}'>{$navnames}</a></div>\n";
else
$display .= "<div id='leftnavon'>{$navnames}</div>\n";
}
if ($display != "")
echo ($display);
else
echo ("Nothing to display.");
?>
I had a friend who helped me out a little bit but he's left town on vacation and didn't tell me till just now, so I'm in a bind because I needed this site done two weeks ago.
Here's what I'm trying to do: You load up the page and it goes through the following code to post the navigation links. It will set a $whatpage variable so it can check that and if it's on the page that the variable is set too, that navigation link will be turned off and highlighted through CSS.
The $pages variable is the info that gets plugged into the end of the URL to set the $whatpage variable. I have 2 problems with the current script.
1) Instead of listing the actual names from the $navnames variable, it's simply putting "Array" in every link name.
2) The $whatpage variable isn't getting reset when you click on a link, so the same link button remains highlighted no matter where you go in the site. I was under the assumption that by putting it at the end of the URL for whatever page you're on. "IE: blah.com?whatpage=thepageyoureon" would reset the $whatpage variable each time, am I wrong on that? I think the problem with this is that because this script is in the header file, it keeps resetting the variable to "news", so it's ignoring the other info. Should I include the variable reset in the actual page where the content is instead?
Anyway, if anyone can help me out with this, I would REALLY appreciate it. I need to get this site up and running but this is the main thing holding me back.
Thanks for your help!!!!
Esch
<?php
$pages = array("news", "aboutthestaff", "directorratings", "forum", "contests", "submissions", "links", "contact");
$navnames = array("News", "About The Staff", "Director Ratings", "Forum", "Contests", "Submissions", "Links", "Contact");
$whatpage = "news";
$display = "";
foreach ($pages as $page){
if ($whatpage != $page)
$display .= "<div id='leftnav'><a href='{$page}.php?whatpage={$page}'>{$navnames}</a></div>\n";
else
$display .= "<div id='leftnavon'>{$navnames}</div>\n";
}
if ($display != "")
echo ($display);
else
echo ("Nothing to display.");
?>