Results 1 to 12 of 12

Thread: [RESOLVED] Opening the right page...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Resolved [RESOLVED] Opening the right page...

    hi sorry i'm a real newbie to php so would like to check this out:

    my index.php page looks like this:

    Code:
    <body>
    <div class="header">
    <?php include ("header.html") ?>
    </div>
    <div id="menu">
    <?php include ("menu_start.html") ?>
    </div>
    <div id="mainbody">
    <?php include ("homebody.html") ?>
    </div>
    <div class="footer">
    <?php include ("footer.html") ?>
    </div>
    so what i want to do is have a link called 'about' on my header.html page but when i click this i want to show 'about.html' in the same place as 'homebody.html' - how do i do this? ie. load a specific page in a specific part of the page??

    thanks

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Opening the right page...

    There are many ways you could do it. You could link to index.php?a=about, and then in your code do:

    Code:
    <div class="header">
    <?php include ("header.html") ?>
    </div>
    <div id="menu">
    <?php include ("menu_start.html") ?>
    </div>
    <div id="mainbody">
    <?php if( isset( $_REQUEST[ "a" ] ) )
    {
        switch( $_REQUEST[ "a" ] )
        {
            case "about":
                include ("about.html"); 
            break;
    
            default:
                include ("homebody.html");
        }
    }
    else
    {
        include ("homebody.html");
    }
    ?>
    </div>
    <div class="footer">
    <?php include ("footer.html") ?>
    </div>
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Re: Opening the right page...

    hmmm, i'd have to put everything into the code there.. is there a way i can call that bit of the page 'mainbody' and then just call something to load the correct page into 'mainbody' - like you would with frames for instance??

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Opening the right page...

    What I would normally do is this have all HTML/PHP for the header and menu be in a file called header.php, and everything for the footer be in footer.php, so all I need to do on every page is:

    PHP Code:
    <?php
        
    require( "header.php" );
    ?>

    <b>Content Here</b>

    <?php
       
    require( "footer.php" ):
    ?>
    Notice that if you have many pages, you're going to have a lot of repetative code in each page.


    I would move restructure it so all of this is in your header file:

    Code:
    <html>
    <head>
    ...
    </head>
    <body>
    <div class="header">
    <?php include ("header.html") ?>
    </div>
    <div id="menu">
    <?php include ("menu_start.html") ?>
    </div>
    <div id="mainbody">
    I'd replace the include for "header.html" with the actual text, and save the lot as header.html.

    And include the following in your footer:

    Code:
    </div>
    <div class="footer">
    <?php include ("footer.html") ?>
    </div>
    </body>
    </html>
    So that you can just include the header, have your content, and then include your footer like I showed in the example above. Much less repetative HTML that way, and much easier to manage when you want to change the layout.
    Last edited by The Hobo; Nov 23rd, 2006 at 11:34 AM.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Opening the right page...

    Quote Originally Posted by wwwfilmfilercom
    hmmm, i'd have to put everything into the code there.. is there a way i can call that bit of the page 'mainbody' and then just call something to load the correct page into 'mainbody' - like you would with frames for instance??
    You could use AJAX, but that'll take a little research and trial and error. Uses JavaScript to make a call to the webserver to retrieve the content. On the callback, you could just replace the content of a DIV with whatever the server returned.

    If you're interested, I'd consider using the Prototype library, or you could simply write your own JS code to do it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Re: Opening the right page...

    lol holy moly - i though php would be able to handle this but ill definitely look into the prototype library thanks!

  7. #7
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Opening the right page...

    Well, using AJAX just to simply go to a new page may not be the best use of AJAX. Most people would probably just do it by having multiple pages (index.php, about.php) and link to those...but if you don't want that, then yeah, look into AJAX.

    If the page is already loaded, PHP is out of the equation. If you want to do something with the page after its loaded, you need something on the client-side. PHP is strictly server-side programming.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Re: Opening the right page...

    Right I'm stuck (again) and even though I've looked at SSI and using <include> or <require> I am having problems organising the structure of my page with PHP. Hopefully you can help:


    The page is split into 4 sections:
    header and footer always stay the same...
    menu has the login form and when logged in shows member/admin links...
    mainbody is where the content loads...


    The bit thats most confusing is menu because I can get one part of the page to change, such as mainbody, but I'm wondering how to keep the menu bit the same whether the user has logged in or not...

    How can I structure this page??
    Please help!!

  9. #9
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Opening the right page...

    Assuming you have some mechanism for determining whether or not someone is logged in, I would do something like this in the menu file:

    Code:
    <a href="">Home</a>
    <?php
    if( user_is_logged_in ) // obviously change this
    {
    ?>
        <a href="">Admin Option #1</a>
        <a href="">Admin Option #2</a>
    <?php
    }
    else
    {
    ?>
        <a href="">Login</a>
    <?php
    }
    ?>
    <a href="">Something Else</a>
    It really doesn't need to be any more complicated than that. You could also have two seperate files, admin_menu.html and standard_menu.html and include() or require() the file depending on whether or not the viewer is logged in.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Re: Opening the right page...

    So I would have:

    Code:
    <?php 
        require( "header.php" ); 
    ?> 
    
    <b>Content Here</b> 
    
    <?php 
       require( "footer.php" ): 
    ?>

    And in header.php:

    Code:
    <html>
    <head>
    ...
    </head>
    <body>
    <div class="header">
    <?php include ("header.html") ?>
    </div>
    <div id="menu">
    <?php include ("menu.php") ?>
    </div>
    And in menu.php:

    Code:
    <a href="">Home</a>
    <?php
    if( user_is_logged_in ) // obviously change this
    {
    <?php 
        require( "admin_menu.html" ); 
    ?> 
    }
    else
    {
    <?php 
        require( "member_menu.html" ); 
    ?> 
    }
    ?>
    <a href="">Something Else</a>
    Is that correct???

  11. #11
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Opening the right page...

    Um...you could do it like that, yes.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Re: Opening the right page...

    Thanks!!!!! I checked that out and it works great FINALLY I've worked this out lol...

Posting Permissions

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



Click Here to Expand Forum to Full Width