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 5 of 5
  1. #1
    axd
    axd is offline
    New Coder
    Join Date
    Mar 2009
    Location
    Leeds, UK
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts

    conditional page displaying

    Hello, I have been banging my head off a few walls trying make something work, and am wondering if you guys have any answers that may help me out. I have "created" a php website (purely from tutorials, my natural coding abilitly ends when the tutorials do unfortunately - but i do have a decent grasp of it and am at least able to understand most things thown at me). Anyway, enough babble, on with the issue at hand...

    i have a menu system which shows subjects and their related pages. 2 menu's in fact, one for public, one for admin. I am tring to include a file onto my main content page (thats the easy bit) but i only want it to be included on pages that are from a certain subject. Any ideas?

    Thanx in advance, i may need to be a bit more definite in my questions. If you need code snippets or anything please ask.


    Dan

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    How does the code know which pages qualify for this additional included file?

  • #3
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Hmm I don't quite understand what you mean. A standard include would be:

    PHP Code:
    include ('blah.php'); 
    Now someone can correct me if I am wrong, but you may be able to call an include inside of a function. I have never tried it,

    But you really don't need to, you can include and not include any part, its up to you.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Its certainly legal to include within a function; however, you may not be able to make use of it after that fact. Include imports its symbols into the current script scope, which would be on a function stack if it was within a function that include was called. That means that when the function is terminated, the stack will crush the symbols.

    I'm actually thinking the OP's question is more along the lines of they have a script generating the links, but would like to be able to change the links based on the current page.
    You'll always be including or evaluating before including. For centralized support, I'd let the inclusion handle the control, so that any changes can be done from a centralized location.
    You'll need to post more information to help us determine what exactly you're trying to acheive.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    axd
    axd is offline
    New Coder
    Join Date
    Mar 2009
    Location
    Leeds, UK
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Sorry for the delay...

    Hi guys, thankyou for the quick response, much appreciated. And apologies for my late reply i have been working away for 2 days so its been kinda hectic... ok heres some code and an explanation of what i aim to do. Hopefully someone can shed some light as to either where i am going wrong, or a simpler solution....

    I have worked out how to change my links depending on which page is being viewed, but i want to include a file only on certain pages within my site. The include file contains a table with text and images on, and the image relates to the page, but not all pages need this include file, only some. 1) is it possible to have an if statement in an include, that is iuncluded inside an if statement?.

    heres what i tried to do



    My main page code.....

    PHP Code:

    <td width="646" id="page" align="center">
    <br> 

    <?php if ($sel_page) { ?>
            
    <h2><?php echo $sel_page['menu_name']; ?></h2>
    <?php include("game_page.php"); ?>
      <div class="page-content">
        <?php echo $sel_page['content']; ?><br><br>
            <?php echo $sel_page['guide']; ?><br><br>
            <?php echo $sel_page['cheat']; ?>
     </div>
                <?php } else { ?>
                    
            <br><br>
                                        <h2> THIS SITE IS CURRENTLY UNDER CONSTRUCTION</h2>

        <?php ?>
      
    </td>
    The file i am trying to include is this.....
    PHP Code:
    <?php include("game_page.php"); ?>

    As it is already contained within an if statement, can i use an if statement withing the include? i tried to and the page just went white when loaded up in FF. I am trying to get it to recognise which pages require the included file by using a tinyint in the database giving a 1 or 0 depending on whether it should be used.

    Here is the code inside the include file....

    PHP Code:
    <table width="600" id="title_table">
        
        <tr>
            <td>
    <table width="300">
        <tr>
            <td> Genre :
            </td>
            <td><?php echo $sel_page['genre']; ?></td>
        </tr>
        <tr>
            <td>Play Here :
            </td>
            <td><a href="<?php echo $sel_page['url']; ?>"><?php echo $sel_page['menu_name']; ?> </a></td>
        </tr>
        
        <tr>
            <td>Score :
            </td>
            <td><?php echo $sel_page['score']; ?></td>
        </tr></table>
            </td>
      


        <td>
     <table width="300">   
        <tr>
            <td>
                
             **** I want to place an image here ****
            </td>
        </tr></table>
        </td>
     </tr>

    </table>

    Any help or ideas would be appreciated

    thankyou

    Dan
    Last edited by Fou-Lu; 03-21-2009 at 12:39 AM. Reason: Wapped in PHP tags


  •  

    Posting Permissions

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