Php Link Refresh Page

Discussion in 'PHP' started by sakto, Jun 27, 2010.

  1. #1
    For illustration purposes i have these 3 codes in a php page (but they not necessarily an "echo" call and can be something else).

    <?php echo "Power"; ?>
    <?php echo "Wealth"; ?>
    <?php echo "Money"; ?>

    What I want is to display only one of them through a link like this; Power | Wealth | Money. When someone click "Power" link, the page refreshes and displays Power. When "Wealth" is clicked the page refreshes and displays Wealth and so on.

    Any help will be appreciated. Have a nice day.
     
    sakto, Jun 27, 2010 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    so the link would be something like

    index.php?get=power

    then the php page would get the right info, display the "menu" again.

    Is that what you mean?
     
    sarahk, Jun 27, 2010 IP
  3. Epiic

    Epiic Greenhorn

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    Along with what sarahk said, you'd also need to code the $_GET[] PHP function.

    Your page would look something like this:

    
    <html>
    <head>
    <title>Index.php</title>
    </head>
    <body>
    <?php
    if($_GET['page']=="power"){
    echo "Power page.";
    }
    else if($_GET['page']=="wealth"){
    echo "Wealth page.";
    }
    else if($_GET['page']=="money"){
    echo "Money page.";
    }
    else {
    echo "Please choose a page.<br />";
    echo "<a href=\"index.php?page=power\">Power</a>. <a href=\"index.php?page=wealth\">Wealth</a>. <a href=\"index.php?page=money\">Money</a>.";
    }
    ?>
    </body>
    </html>
    
    PHP:
     
    Epiic, Jun 27, 2010 IP
  4. sakto

    sakto Active Member

    Messages:
    1,517
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    90
    #4
    Thank you both of you.

    Anyway, I have tested the code but when I click on the link I am redirected to the homepage. I used the codes on a different page other than the home page.
     
    Last edited: Jun 28, 2010
    sakto, Jun 28, 2010 IP
  5. Epiic

    Epiic Greenhorn

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    The way I coded my file was assuming that this would be a one page kind of site. Since you have multiple pages, you'd have to change the index.php?page=whatever in the code I wrote. If you still need help feel free to PM me.
     
    Epiic, Jun 28, 2010 IP
  6. sakto

    sakto Active Member

    Messages:
    1,517
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    90
    #6
    It is working now. I have just inadvertently placed a slash. Thank you.
     
    sakto, Jun 28, 2010 IP