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
    New Coder
    Join Date
    Jul 2012
    Posts
    85
    Thanks
    53
    Thanked 0 Times in 0 Posts

    Don't bother loading if variable requirements not met

    I was wonder if there was a way to only load a chunk of the page if a variable is set to something (let's just say "1").

    So like:

    PHP Code:
    <?php
    if == "1" {
       
    load(#something);
    }
    ?>

    <div id="page""></div>
    <div id="something"></div>
    Thank you!

  • #2
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,267
    Thanks
    10
    Thanked 277 Times in 276 Posts
    Something like this?
    Code:
    <?php
    if (x == "1") {
    ?>
    
    <h1>X was equal to 1</h1>
    
    <?php
    }
    ?>
    
    <div id="page""></div>
    <div id="something"></div>

  • Users who have thanked tracknut for this post:

    RonnyNishimoto (07-31-2012)

  • #3
    New Coder
    Join Date
    Jul 2012
    Posts
    85
    Thanks
    53
    Thanked 0 Times in 0 Posts


    I know everybody is laughing at me right now

    Thank you so much tracknut!

  • #4
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    variables should start with a $
    you could just echo it too:

    PHP Code:
    <?php
    if ($x == "1") {
       echo 
    'something';
    }
    ?>

    <div id="page""></div>
    <div id="something"></div>
    it is also fine inline:

    PHP Code:
    <div id="page""></div>
    <div id="something"><?php if ($x == "1") {echo 'something';}?></div>
    Last edited by Arcticwarrio; 07-31-2012 at 03:50 PM. Reason: missed the brackets

  • #5
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    You can also put the content in another page and use include or require to put it in:

    PHP Code:
     if ($x == 1) include('path/to/file.ext'); 
    Remember you don't need quotes around a number unless that number is explicitly a string... just because PHP is type loose doesn't mean you should be!


  •  

    Posting Permissions

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