...

View Full Version : Don't bother loading if variable requirements not met



RonnyNishimoto
07-31-2012, 04:24 AM
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
if x == "1" {
load(#something);
}
?>

<div id="page""></div>
<div id="something"></div>


Thank you!

tracknut
07-31-2012, 04:40 AM
Something like this?


<?php
if (x == "1") {
?>

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

<?php
}
?>

<div id="page""></div>
<div id="something"></div>

RonnyNishimoto
07-31-2012, 05:07 AM
:)

I know everybody is laughing at me right now :D

Thank you so much tracknut!

Arcticwarrio
07-31-2012, 03:48 PM
variables should start with a $
you could just echo it too:



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

<div id="page""></div>
<div id="something"></div>

it is also fine inline:



<div id="page""></div>
<div id="something"><?php if ($x == "1") {echo 'something';}?></div>

Keleth
07-31-2012, 04:15 PM
You can also put the content in another page and use include or require to put it in:


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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum