Nested IF statement... challenge

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
rasstag
Forum Newbie
Posts: 2
Joined: Wed Jan 11, 2012 1:54 pm

Nested IF statement... challenge

Post by rasstag »

Hi folks… remember when you ‘first’ began to learn PHP… that’s where I’m at now… so the ‘obvious’ may not be so at this point.

I’m struggling with two IF statements… any help would be appreciated.

Originally I was building lines of output that ultimately would be sent via email, the code would loop through ‘values’ and build the “$delivery_info” line based on the contents of $thisFieldValue.; (..the content of which might be something like “ASAP”) … the code below works..

if ($thisFieldName == "Del Date") $delivery_info .= $thisFieldValue.;

..ok… so now I’m trying to make it a ‘bit’ smarter and if the user failed to enter a ‘Delivery Date’… I want to change the value that ends up in $delivery_info with the string “<Field Empty>”. My attempts to add a working sub-IF statement have been less than successful. …my non-working code follows..

if ($thisFieldName == "Del Date") {
if ($thisFieldValue == "") {
$delivery_info .= "<Field Empty>";
} else {
$delivery_info .= $thisFieldValue.;
}
}

If I comment out the inner IF statement… the remaining code works… so I’m shooting myself in the foot somewhere in the inner IF structure.

if ($thisFieldName == "Del Date") {
// if ($thisFieldValue == "") {
// $delivery_info .= "<Field Empty>";
// } else {
// $delivery_info .= $thisFieldValue.;
// }
}

I need a fresh pair of eyes to help me with this please.

Many thanks,

Rasstag
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Nested IF statement... challenge

Post by twinedev »

You have a period at the end of this line:

Code: Select all

$delivery_info .= $thisFieldValue.;
                                 ^
Another method:

Code: Select all

if ($thisFieldName == "Del Date") {
	$delivery_info .= ($thisFieldValue == "") ? "<Field Empty>" : $thisFieldValue;
}
-Greg
rasstag
Forum Newbie
Posts: 2
Joined: Wed Jan 11, 2012 1:54 pm

Re: Nested IF statement... challenge

Post by rasstag »

... thank you SO much twinedev… sure enough that little ‘punctuation’ was making it not work.. (and making me crazy).

I owe you a cold one when next we meet at the tavern!

Be safe my friend.

Rasstag
Post Reply