T_VARIABLE problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
denhamd2
Forum Newbie
Posts: 12
Joined: Thu Jun 10, 2004 9:59 am

T_VARIABLE problem

Post 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
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

Code: Select all

{echo '<div class="ps">'.$_SESSION["order1"].'</div>'}; 
//OR
{echo "<div class="ps">".$_SESSION["order1"]."</div>"}; //<==LAST QUOTE!
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

or

Code: Select all

(!empty($_SESSION["order1"])) ? echo '<div class="ps">'.$_SESSION["order1"].'</div>' : '';
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

patrikG

what do you call thoes conditional statements again ...i totally forgot

the ()?":'';
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

It's the ternary operator.
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

thanks
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

or:

Code: Select all

if ($_SESSION['order1'] == "") {} else {echo "<div class="ps">{$_SESSION['order1']}</div>"};
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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 ;)
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post 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
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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 {}
Post Reply