Jump to content

IF else Menu Selected [SOLVED]


attila2452

Recommended Posts

Okay so i've had a previous website :http://attilahajzer.comli.com/and I would like to use that MENU selected PHP part from there. but i cant remember how i did it, i also dont know what Hosting service i used so i cant get access to the PHP file. ive tried a bunch of ways to trying to get it but cant.and i now im running into the issue where im not that good at php and can't think of how i would do it. this is what i've come up with

<?php	if($_GET["page"] == "home"){		echo"background-color:#000;color:#FFF;";	}elseif($_GET["page"] == "about"){		echo"background-color:#000;color:#FFF;";	}elseif($_GET["page"] == "contact"){		echo"background-color:#000;color:#FFF;";	}elseif($_GET["page"] == "store"){		echo"background-color:#000;color:#FFF;";	}elseif($_GET["page"] == "affiliates"){		echo"background-color:#000;color:#FFF;";	}else ($_GET["page"] == ""){		echo"background-color:none;color:#035a91;";		}?>

am i missing anything? or am i doing it wrong?Im getting this error

Parse error: syntax error, unexpected '{' in /home/attilah/public_html/sites/Antique/menu.php on line 12
<ul>	<li><a href="?page=home"<?php if(isset($_GET["page"]) && $_GET["page"] == "home"){echo"style='background-color: #000; color: #FFF;'";}else{echo"style='background-color:none;color:#035a91;'"; }?>>Home</a></li>	<li><a href="?page=about"<?php if(isset($_GET["page"]) && $_GET["page"] == "about"){echo"style='background-color: #000; color: #FFF;'";}else{echo"style='background-color:none;color:#035a91;'";} ?>>About</a></li>	<li><a href="?page=contact"<?php if(isset($_GET["page"]) && $_GET["page"] == "contact"){echo"style='background-color: #000; color: #FFF;'";}else{echo"style='background-color:none;color:#035a91;'";} ?>>Contact</a></li>	<li><a href="?page=store"<?php if(isset($_GET["page"]) && $_GET["page"] == "store"){echo"style='background-color: #000; color: #FFF;'";}else{echo"style='background-color:none;color:#035a91;'";} ?>>Store</a></li>	<li><a href="?page=affiliates"<?php if(isset($_GET["page"]) && $_GET["page"] == "affiliates"){echo"style='background-color: #000; color: #FFF;'";}else{echo"style='background-color:none;color:#035a91;'";} ?>>Affilialtes</a></li></ul>

Link to comment
Share on other sites

I'm confused, so is this actual code in your PHP page?

<ul>	<li><a href="?page=home"<?php if(isset($_GET["page"]) && $_GET["page"] == "home"){echo"style='background-color: #000; color: #FFF;'";}else{echo"style='background-color:none;color:#035a91;'"; }?>>Home</a></li>	<li><a href="?page=about"<?php if(isset($_GET["page"]) && $_GET["page"] == "about"){echo"style='background-color: #000; color: #FFF;'";}else{echo"style='background-color:none;color:#035a91;'";} ?>>About</a></li>	<li><a href="?page=contact"<?php if(isset($_GET["page"]) && $_GET["page"] == "contact"){echo"style='background-color: #000; color: #FFF;'";}else{echo"style='background-color:none;color:#035a91;'";} ?>>Contact</a></li>	<li><a href="?page=store"<?php if(isset($_GET["page"]) && $_GET["page"] == "store"){echo"style='background-color: #000; color: #FFF;'";}else{echo"style='background-color:none;color:#035a91;'";} ?>>Store</a></li>	<li><a href="?page=affiliates"<?php if(isset($_GET["page"]) && $_GET["page"] == "affiliates"){echo"style='background-color: #000; color: #FFF;'";}else{echo"style='background-color:none;color:#035a91;'";} ?>>Affilialtes</a></li></ul>

What does it look like after the page has rendered? Are all quotes accounted for, do you seen anything strange? How is $_GET["page"] being passed to the page?From looking at this code however,
<?php	if($_GET["page"] == "home"){		echo"background-color:#000;color:#FFF;";	}elseif($_GET["page"] == "about"){		echo"background-color:#000;color:#FFF;";	}elseif($_GET["page"] == "contact"){		echo"background-color:#000;color:#FFF;";	}elseif($_GET["page"] == "store"){		echo"background-color:#000;color:#FFF;";	}elseif($_GET["page"] == "affiliates"){		echo"background-color:#000;color:#FFF;";	}else ($_GET["page"] == ""){		echo"background-color:none;color:#035a91;";		}?>

the error is the ending conditional. If you are going to end it with else, then it should just look like this

	}else{		echo"background-color:none;color:#035a91;";		}

or this:

	}else if ($_GET["page"] == ""){		echo"background-color:none;color:#035a91;";		}

I think you would also be wanting to wrap the values of each CSS property in quotes.

Link to comment
Share on other sites

This can all be done much more easily by giving each link a class/ID, and then using CSS to set the relevant class to a different color:

<style type="text/css">	a {		background-color:none;		color:#035a91;	}	a#<?php echo $_GET['page']; ?>_link {		background-color:#000;		color:#FFF;	}</style>

<ul>	<li><a href="?page=home" id="home_link">Home</a></li>	<!-- ... --></ul>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...