Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts

    Dynamic Menu, (If's and Else's)

    PHP Code:
    <?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
    Last edited by the-dream; 01-13-2008 at 04:29 PM. Reason: Missed a bit of code off.

  • #2
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    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!

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    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
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •