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 10 of 10
  1. #1
    mjs
    mjs is offline
    New Coder
    Join Date
    Jan 2010
    Posts
    97
    Thanks
    17
    Thanked 0 Times in 0 Posts

    could some one help me with my switch page ??

    I am wondering if anyone out there can help with my switch page Please?

    Code:
    <html>
    <body>
    
    <?php include("templates/header.php"); ?>
    <!-- link Menu -->
    <a href="/default.php">Home</a>
    <a href="faq/tutorials.php">Tutorials</a>
    <a href="/references.php">References</a>
    <a href="misc/examples.php">Examples</a>
    <a href="misc/about.php">About Us</a>
    <a href="/contact.php">Contact Us</a> 
    <!-- end link menu -->
    
    <h1>Welcome to my home page!</h1>
    
    <?php include("functions/body.php"); ?>
    
    <?php include("templates/footer.php"); ?>
    </body>
    </html>
    now, how to call link menu e.g (default.php, tutorials.php, etc) by dinamic change the body.php?

    i tyr use switch page i.e.

    PHP Code:
    <?
    $page 
    $_GET['page'];
    if (empty(
    $page)) { $page $_POST['page']; }
    if (empty(
    $page)) { $page "body"; }

    switch (
    $page) {

        default:
            
    $pagea[] = include("functions/body.php");
        break;

        case 
    "orderform":
            
    $pagea = include("/references.php");
        break;

        case 
    "orderform":
            
    $pagea = include("misc/about.php");
        break;
    }
    ?>
    but it's seem doesn't work...
    for any idea would be welcome and many thanks

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Are you trying to make something similar to the one explained at I need a dynamic header, footer, sidebar....Currently Static
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    You can't assign page contents from an include to a variable. You need to do it with something like file_get_contents
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #4
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Quote Originally Posted by JAY6390 View Post
    You can't assign page contents from an include to a variable. You need to do it with something like file_get_contents
    Yes you can.

    file1.php
    PHP Code:
    <?php

    // do some processing up here

    return 'John';

    // everything below the return will not get
    // processed for this particular file
    file2.php
    PHP Code:
    $name = include 'file1.php';

    echo 
    $name// John 
    Though we are not sure the OP is doing this.
    Last edited by kbluhm; 01-23-2010 at 02:05 PM.

  • #5
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    lol returning a value isn't quite the same as getting an entire files content, but I know what you mean. I'd find it pretty pointless returning a value for each switch when the code could be put in the switches themselves
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #6
    mjs
    mjs is offline
    New Coder
    Join Date
    Jan 2010
    Posts
    97
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Hi... I very thank for joining my question... bless and peace upon you all..

    abduraooft
    i'm not sure whether your link that what i need, but it seem different in my mind and also nothing clear there so i absolutely don't understand what the end.

    JAY6390
    file_get_contents ?? i ever heard it, but i blind, i just need more samples about file_get_contents with hopefully solve my case...

    kbluhm
    you put short code and with surely can solve my problem... but definitely i don't know how to start from your suggestion... would you make it more clear to me?

  • #7
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    if you need examples the manual is a great place to start
    http://www.php.net/file_get_contents
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #8
    mjs
    mjs is offline
    New Coder
    Join Date
    Jan 2010
    Posts
    97
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by JAY6390 View Post
    if you need examples the manual is a great place to start
    http://www.php.net/file_get_contents
    Nice guidance, i appreciate all your attentions..

    n now i put what i catch from there:

    PHP Code:
    <?php
    $file 
    file_get_contents('./people.txt'FILE_USE_INCLUDE_PATH);
    ?>
    Code:
    <html>
    <body>
    
    <?php include("templates/header.php"); ?>
    <!-- link Menu -->
    <a href="/default.php">Home</a>
    <a href="faq/tutorials.php">Tutorials</a>
    <a href="/references.php">References</a>
    <a href="misc/examples.php">Examples</a>
    <a href="misc/about.php">About Us</a>
    <a href="/contact.php">Contact Us</a> 
    <!-- end link menu -->
    
    <h1>Welcome to my home page!</h1>
    PHP Code:
    <?php
    $file 
    file_get_contents('faq/tutorials.php'FILE_USE_INCLUDE_PATH);
    $file file_get_contents('references.php'FILE_USE_INCLUDE_PATH);
    $file file_get_contents('misc/examples.php'FILE_USE_INCLUDE_PATH);
    ?>
    Code:
    <?php include("templates/footer.php"); ?>
    </body>
    </html>
    it seem doesn't work, may i failed understand? help..

  • #9
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    You need to echo the $file
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #10
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    If you use file_get_contents() on a local PHP file, any PHP code in the file will not be processed; it will be returned as plain text.

    You need to include the file you wish to display.

    If you want to capture the output of a file to be assigned to a variable:
    PHP Code:
    ob_start();
    include 
    './body.php';
    $source ob_get_clean();

    // $source now contains the parsed output of `./body.php`

    echo $source
    Last edited by kbluhm; 01-23-2010 at 03:32 PM.


  •  

    Posting Permissions

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