[PHP] Nested IFs Problem
I have the following nested ifs: if ($row['date'] '2005-10-02') { if ($row['time'] '12:00') { if ($row['field'] == 'P5' ) { echo td class=\tabletextbluebg\Success; } } } else { echo td class=\tabletextred\Failed; } /td Whenever the 3 if statements are true, I always get the correct Success to echo. However, if any or all of the if statements are false, I never get Failed to echo. I know it's something simple, but I just can't see it at the moment. TIA Albert Padley -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Nested IFs Problem
why not rewrite it to be more concise... i can't see a problem at the moment. are you sure you can do a comparison operator on the '12:00' and '2005-10-02' string?? Maybe if you are using 24 hr format you could just get rid of the : on both sides of the operator to have the properly evaluated... do the same for the date comparison. just try each if statement individually. then, when you find the problem, rewrite like this: if ((putFirstExpressionHere) (putSecondExpressionHere) (putThirdExpressionHere)) { // success } else { // failure } Jordan On Aug 31, 2005, at 3:05 PM, Albert Padley wrote: if ($row['date'] '2005-10-02') { if ($row['time'] '12:00') { if ($row['field'] == 'P5' ) { echo td class=\tabletextbluebg\Success; } } } else { echo td class=\tabletextred\Failed; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Nested IFs Problem
I have the following nested ifs: if ($row['date'] '2005-10-02') { if ($row['time'] '12:00') { if ($row['field'] == 'P5' ) { echo td class=\tabletextbluebg\Success; } } } else { echo td class=\tabletextred\Failed; } /td Whenever the 3 if statements are true, I always get the correct Success to echo. However, if any or all of the if statements are false, I never get Failed to echo. I know it's something simple, but I just can't see it at the moment. TIA Albert Padley Just shooting from the hip here, you will never get the Failed echo unless the FIRST if is false. JM -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [SPAM] - [PHP] Nested IFs Problem - Bayesian Filter detected spam
Albert Padley wrote: I have the following nested ifs: if ($row['date'] '2005-10-02') { if ($row['time'] '12:00') { if ($row['field'] == 'P5' ) { echo td class=\tabletextbluebg\Success; } } } else { echo td class=\tabletextred\Failed; } /td Whenever the 3 if statements are true, I always get the correct Success to echo. However, if any or all of the if statements are false, I never get Failed to echo. Once the first if statement is evaluated as true, the else statement will never be executed -- regardless of the outcome of the two nested ifs. I am not sure what you are trying to accomplish here, but perhaps all three of your if conditions should be combined into one if condition ANDed () together? Or maybe the if...elseif...else structure is what you need. Hope this helps. Justin I know it's something simple, but I just can't see it at the moment. TIA Albert Padley -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Nested IFs Problem
Albert Padley wrote: Whenever the 3 if statements are true, I always get the correct Success to echo. However, if any or all of the if statements are false, I never get Failed to echo. I know it's something simple, but I just can't see it at the moment. The code is doing exactly what you told it to do. To make it do what you what you seem to want it to do, get rid of the nested IFs and place all three tests within a single IF. -- == Eric Gorr === http://www.ericgorr.net === Government is not reason, it is not eloquence, it is force; like fire, a troublesome servant and a fearful master. - George Washington == Insults, like violence, are the last refuge of the incompetent... === -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [SPAM] - [PHP] Nested IFs Problem - Bayesian Filter detected spam
Justin Jordan, Thanks. The was what I needed. Albert Padley On Aug 31, 2005, at 2:27 PM, Justin Francis wrote: Albert Padley wrote: I have the following nested ifs: if ($row['date'] '2005-10-02') { if ($row['time'] '12:00') { if ($row['field'] == 'P5' ) { echo td class=\tabletextbluebg\Success; } } } else { echo td class=\tabletextred\Failed; } /td Whenever the 3 if statements are true, I always get the correct Success to echo. However, if any or all of the if statements are false, I never get Failed to echo. Once the first if statement is evaluated as true, the else statement will never be executed -- regardless of the outcome of the two nested ifs. I am not sure what you are trying to accomplish here, but perhaps all three of your if conditions should be combined into one if condition ANDed () together? Or maybe the if...elseif...else structure is what you need. Hope this helps. Justin I know it's something simple, but I just can't see it at the moment. TIA Albert Padley -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Nested IFs Problem
Jim Moseby [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I have the following nested ifs: if ($row['date'] '2005-10-02') { if ($row['time'] '12:00') { if ($row['field'] == 'P5' ) { echo td class=\tabletextbluebg\Success; } // This, if there was anything, would be executed if the date and the time condition is true and the field is false } // this would be executed if the date condition is true and the time is false, regardless of what the field condition is } else { // this would be executed only if the date condition is false, regardless of the other conditions echo td class=\tabletextred\Failed; } /td So, you better put all the conditions in a single if, joined by 'and' or : if ($row['date'] '2005-10-02' $row['time'] '12:00' $row['field'] == 'P5' ) { That would do what you want -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php