Links in php

Discussion in 'PHP' started by JBO, Apr 20, 2006.

  1. #1
    I'm creating my first php site and I have following problem:

    I divided my webpage in 2 regions (table-based): on the left, a region where I put the links to my pages "home", "contact" etc.

    These links have to link to my right side:

    eg: when I click the link "home", my right page should load the php script: home.php. The left side has to remain the same.

    Can i do it in the way that I use a variable which changes on every click:
    eg: when clicking "home", the variable takes the value "home", when clicking another link, the variable changes to another value. This value will be used to change the right part of my site.

    I hope I'm clear in what I want. Now my question is: is this possible in php do do it this way? How?

    thanks
     
    JBO, Apr 20, 2006 IP
  2. MamboCube

    MamboCube Peon

    Messages:
    242
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    in know what you mean, I use this sytem for my sites

    youll need a seperate file, which i call case.php

    this file would have:

    <?php
    switch($_GET["action"])
    {
    	  
       /*-----------------------------------------------------------------
          Page 1
         -----------------------------------------------------------------*/
       case 'page1':
          include("page1.php");
          break;
    	  
       /*-----------------------------------------------------------------
          Page 2
         -----------------------------------------------------------------*/
       case 'page2':
          include("page2.php");
          break;
       
       /*-----------------------------------------------------------------
          Default
         -----------------------------------------------------------------*/
       default:
             include("homepage.php");
             break;
    }
    ?>
    PHP:
    here you are setting an 'action' to open specific pages.

    Now, to open the pages, you need to assign the action in your links.

    so you would use the following:

    <a href="index.php?action=page1">Page 1</a>
    HTML:
    Also, you need to include this case file in your index page, remember that the content will load wherever you put this case file :)

    Im not saying this IS the way, but its the way I do it.

    I actually use a slightly more complicated way where you only have one object in the switch loop, but I wont go into that now.

    Im sure there will be some DP members who will find a couple of things wrong with how I do it lol!

    Anyways, good luck!
     
    MamboCube, Apr 20, 2006 IP
    kkibak likes this.
  3. JBO

    JBO Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the trouble! It really worked!
     
    JBO, Apr 20, 2006 IP
  4. MamboCube

    MamboCube Peon

    Messages:
    242
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #4
    it did? cool!

    thought maybe i didnt explain it well enough lol!

    now youve got that sorted, you may want to look into mod_rewrite for SEO purposes :)
     
    MamboCube, Apr 20, 2006 IP