php navigation

Discussion in 'PHP' started by dean5000v, Mar 3, 2008.

  1. #1
    hey well i'm not very good at PHP but I've decided to create a PHP navigation and i'm basically echoing the page data onto the page is there anyway i could like echo an whole page content on there with like a include or something, here is my code if anyone else knows any other ways to do a navigation like this please let me know.
    
     <BODY><div id="container">
    <div id="navigation">
    <ul>
    <li><a href="?">Home</a></li>
    <li><a href="?page=about">About</a></li>
    <li><a href="?page=products">Products</a></li>
    <li><a href="?page=contact">Contact</a></li></ul>
    </div>
    <?php switch($_GET['page']) {
    case "about":
    echo "<div id=\"content\">about page content goes here</div>";
    break;
    
    case "products":
    echo "<div id=\"content\">products page goes here</div>";
    break;
    
    case "contact":
    echo "<div id=\"content\">contact page goes here</div>";
    break;
    
    default:
    echo "<div id=\"content\">Home page goes here </div>";
    break;
    }?>
    </div>
    
    Code (markup):
    ]
     
    dean5000v, Mar 3, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Just replace your echo with:
    
    include 'some-page.php';
    
    PHP:
     
    nico_swd, Mar 3, 2008 IP
  3. Morishani

    Morishani Peon

    Messages:
    239
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    A better way to do what you want is :

    
    $aPages = array("about"=>true,"products"=>true,"contact"=>true);
    if (isset($_GET['page']))
    	if ($aPages[$_GET['page']])
    		include($_GET['page']."php");
    	else
    		include("default.php");
    else
    	include("default.php");
    
    PHP:
    Good luck :)
     
    Morishani, Mar 3, 2008 IP
  4. dean5000v

    dean5000v Peon

    Messages:
    201
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hey ive had a lil play around with the code you gave me keep getting errors with the include, i was wondering if you could tell me which lines on there i should change to link to contact.php and stuff thanks.
     
    dean5000v, Mar 3, 2008 IP
  5. dean5000v

    dean5000v Peon

    Messages:
    201
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ok ive got the code working its just now when i change one the links to about.php it changes 3 of my navigation links to direct to that page when i only wont one of the links to direct to that oage, could u tell me which link parts i change in your code thanks.
     
    dean5000v, Mar 3, 2008 IP