Forum Moderators: coopster
I'm trying to create a PHP menu that is called as an include file. Depending on what page is displaying (calling) it, the menu will display an alternate image (different color in this case) indicating what page the user is on.
I have done this in ASP, but can't seem to get it to work in PHP - any help is greatly appreciated.
In ASP a sample for the code will look like this:
<% if page="home_page" then %>
<td><a href="index.php" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage('navigation_r1_c1','','navigation/navigation_r1_c1_f2.gif',1);"><img name="navigation_r1_c1" src="navigation/navigation_r1_c1_f2.gif" width="71" height="12" border="0" alt="home page"></a></td>
<% else %>
<td><a href="index.php" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage('navigation_r1_c1','','navigation/navigation_r1_c1_f2.gif',1);"><img name="navigation_r1_c1" src="navigation/navigation_r1_c1.gif" width="71" height="12" border="0" alt="home page"></a></td>"
<% end if %>
I am trying this in PHP but with no success:
<?php
if ( $page_name =="home_page" )
{
$home_navigation ="<td><a href="index.php" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage('navigation_r1_c1','','navigation/navigation_r1_c1_f2.gif',1);"><img name="navigation_r1_c1" src="navigation/navigation_r1_c1_f2.gif" width="71" height="12" border="0" alt="home page"></a></td>";
}else{
$home_navigation = "<td><a href="index.php" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage('navigation_r1_c1','','navigation/navigation_r1_c1_f2.gif',1);"><img name="navigation_r1_c1" src="navigation/navigation_r1_c1.gif" width="71" height="12" border="0" alt="home page"></a></td>";
}
echo $home_navigation;
?>
------------------------------------------------
I've created the following variable in the PHP home page (the home page calls the navigation include file):
<?php
$page_name = "home_page";
?>
In ASP I would do it like this on the page the called the navigation include file:
<% page_name="home_page"%>
I believe I'm creating an error when I create the variable "home_page" in the page that is calling the PHP include file but I'm not sure about this.
Thanks in advance for any help you can provide.
Scott
One other thing. When you set a variable, you MUST escape all the quotes (replace all " with \") otherwise you are going to get errors. For more information on this look here [us3.php.net]
if($page == "home_page") {
$source = "navigation/navigation_r1_c1_f2.gif";
}
else {
$source = "navigation/navigation_r1_c1.gif";
}
echo "<td><a href=\"index.php\" onMouseOut=\"MM_swapImgRestore();\" onMouseOver=\"MM_swapImage('navigation_r1_c1','','navigation/navigation_r1_c1_f2.gif',1);\"><img name=\"navigation_r1_c1\" src=\"".$source."\" width=\"71\" height=\"12\" border=\"0\" alt=\"home page\"></a></td>";