Page 1 of 1
T_VARIABLE problem
Posted: Thu Jun 10, 2004 9:59 am
by denhamd2
hi,
please could you have a look at this code and tell me how i could fix it? its something to do with the session variable being inside the else brackets:
if ($_SESSION["order1"] == "") {} else {echo "<div class=\"ps\">$_SESSION["order1"]</div>};
it would greatly be appreciated,
dave
Posted: Thu Jun 10, 2004 10:04 am
by PrObLeM
Code: Select all
{echo '<div class="ps">'.$_SESSION["order1"].'</div>'};
//OR
{echo "<div class="ps">".$_SESSION["order1"]."</div>"}; //<==LAST QUOTE!
Posted: Thu Jun 10, 2004 10:06 am
by patrikG
or
Code: Select all
(!empty($_SESSION["order1"])) ? echo '<div class="ps">'.$_SESSION["order1"].'</div>' : '';
Posted: Thu Jun 10, 2004 10:16 am
by PrObLeM
patrikG
what do you call thoes conditional statements again ...i totally forgot
the ()?":'';
Posted: Thu Jun 10, 2004 10:22 am
by patrikG
It's the ternary operator.
Posted: Thu Jun 10, 2004 10:25 am
by PrObLeM
thanks
Posted: Thu Jun 10, 2004 1:59 pm
by Illusionist
or:
Code: Select all
if ($_SESSION['order1'] == "") {} else {echo "<div class="ps">{$_SESSION['order1']}</div>"};
Posted: Thu Jun 10, 2004 5:21 pm
by d3ad1ysp0rk
Illusionist wrote:or:
Code: Select all
if ($_SESSION['order1'] == "") {} else {echo "<div class="ps">{$_SESSION['order1']}</div>"};
not really
patricks works the best, because it only checks one thing, and then does something if it's right. you have a if statement there for no reason, just a waste of space

Posted: Thu Jun 10, 2004 5:30 pm
by PrObLeM
LiLpunkSkateR wrote:
not really
patricks works the best, because it only checks one thing, and then does something if it's right. you have a if statement there for no reason, just a waste of space

I concur
Posted: Thu Jun 10, 2004 10:34 pm
by Illusionist
my example was more showing that he could use what he already had, and that he didn't have to close anything to include $_POST['whatever'] in the echo by using the braces {}