...

View Full Version : Dynamic Menu, (If's and Else's)



the-dream
01-13-2008, 04:25 PM
<?php

if($_SERVER["PHP_SELF"] == '/index.php') {
$image = 'images/overview-selected.png';
$link = '';
$linky = '';
} else {
$image = 'images/overview.png';
$link = '<a href="index.php">';
$linky = '</a>';
}

if($_SERVER["PHP_SELF"] == '/visits.php') {
$image1 = 'images/visits-selected.png';
$link1 = '';
$linky1 = '';
} else {
$image1 = 'images/visits.png';
$link1 = '<a href="visits.php">';
$linky1 = '</a>';

}

if($_SERVER["PHP_SELF"] == '/pages.php') {
$image2 = 'images/pages-selected.png';
$link2 = '';
$linky2 = '';
} else {
$image2 = 'images/pages.png';
$link2 = '<a href="pages.php">';
$linky2 = '</a>';
}

if($_SERVER["PHP_SELF"] == '/code.php') {
$image3 = 'images/code-selected.png';
$link3 = '';
$linky3 = '';
} else {
$image3 = 'images/code.png';
$link3 = '<a href="code.php">';
$linky3 = '</a>';
}

?>

<?php echo $link; ?><img src="<?php echo $image; ?>" border="0" /><?php echo $linky; ?><?php echo $link1; ?><img src="<?php echo $image1; ?>" border="0" /><?php echo $linky1; ?><?php echo $link2; ?><img src="<?php echo $image2; ?>" border="0" /><?php echo $linky2; ?><?php echo $link3; ?><img src="<?php echo $image3; ?>" border="0" /><?php echo $linky3; ?>

Hey Guys, I am trying to make the above code work, for example if you are on the page index.php then to display an image but if you are on code.php to display another! I don't know weather I have done this right, or if i have over complicated it.

Please Help!

Thanks,
~ Christian

the-dream
01-13-2008, 04:34 PM
Done it, really sorry!

I didn't know that $_SERVER['PHP_SELF']; when used doesn't just return /file.php it returns /folder/file.php sorry!

abduraooft
01-13-2008, 04:42 PM
Hope you are trying to achieve the result of this simple methods (CSS/PHP)
http://bonrouge.com/~currentcss
http://bonrouge.com/br.php?page=current



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum