Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-31-2012, 04:24 AM   PM User | #1
RonnyNishimoto
New Coder

 
Join Date: Jul 2012
Posts: 85
Thanks: 53
Thanked 0 Times in 0 Posts
RonnyNishimoto is an unknown quantity at this point
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!
RonnyNishimoto is offline   Reply With Quote
Old 07-31-2012, 04:40 AM   PM User | #2
tracknut
Regular Coder

 
Join Date: Aug 2006
Posts: 891
Thanks: 4
Thanked 205 Times in 204 Posts
tracknut is an unknown quantity at this point
Something like this?
Code:
<?php
if (x == "1") {
?>

<h1>X was equal to 1</h1>

<?php
}
?>

<div id="page""></div>
<div id="something"></div>
tracknut is offline   Reply With Quote
Users who have thanked tracknut for this post:
RonnyNishimoto (07-31-2012)
Old 07-31-2012, 05:07 AM   PM User | #3
RonnyNishimoto
New Coder

 
Join Date: Jul 2012
Posts: 85
Thanks: 53
Thanked 0 Times in 0 Posts
RonnyNishimoto is an unknown quantity at this point


I know everybody is laughing at me right now

Thank you so much tracknut!
RonnyNishimoto is offline   Reply With Quote
Old 07-31-2012, 03:48 PM   PM User | #4
Arcticwarrio
Regular Coder

 
Arcticwarrio's Avatar
 
Join Date: May 2012
Location: UK
Posts: 583
Thanks: 15
Thanked 65 Times in 65 Posts
Arcticwarrio is on a distinguished road
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
Arcticwarrio is offline   Reply With Quote
Old 07-31-2012, 04:15 PM   PM User | #5
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
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!
Keleth is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:40 PM.


Advertisement
Log in to turn off these ads.