Page 1 of 1

[SOLVED] One works, the other doesn't

Posted: Sat Jun 19, 2004 4:11 pm
by ChangingLINKS
I have this bit of code that works half of the time.
If pay='C' it works.
If pay='CA' it does not work.

Code: Select all

elseif( (strcasecmp($myrow['pay'], "C") == 0 ||
           strcasecmp($myrow['pay'], "CA") == 0) 
           && strcasecmp($myrow['linked'], "Y") == 0 
           && in_array($myrow['code'], array(200,302) ) 
) {
		    	echo "commercial";
}
Can anyone tell me how to make it work when pay='CA'?
[edit=Weirdan] please use

Code: Select all

tags for php code [/edit] [/color]

Posted: Sat Jun 19, 2004 9:48 pm
by anjanesh
Does this work ?

Code: Select all

elseif( (strtoupper($myrow['pay']=="C") || 
           strtoupper($myrow['pay']=="CA") == 0) 
           && strtoupper($myrow['linked']=="Y") == 0 
           && in_array($myrow['code'], array(200,302) ) 
) { 
             echo "commercial"; 
}

Posted: Sat Jun 19, 2004 10:09 pm
by feyd
anjanesh wrote:Does this work ?

Code: Select all

elseif( (strtoupper($myrow['pay']=="C") || 
           strtoupper($myrow['pay']=="CA") == 0) 
           && strtoupper($myrow['linked']=="Y") == 0 
           && in_array($myrow['code'], array(200,302) ) 
) { 
             echo "commercial"; 
}
you have some logic errors in there, friend.

Posted: Sat Jun 19, 2004 10:25 pm
by feyd
well.. the original works for me.. I don't know why it doesn't work for you..

Posted: Sun Jun 20, 2004 1:17 am
by ChangingLINKS
Yeah. I try not to post the easy questions.

Even if I change the "C" to "CA" it still doesn't work.
I can use phpmyAdmin to select the records with "CA"
(so there is not capitalization error or extra space character in the cell).

I guess there is no syntax error and no one here can help.
I will post a followup if I can find a solution.

Posted: Sun Jun 20, 2004 1:23 am
by feyd
just for a note, this is the code I ran to test it...

Code: Select all

<?php

$myrow['pay'] = 'AB';
$myrow['linked'] = 'Y';
$myrow['code'] = 200;

if( (strcasecmp($myrow['pay'], "C") == 0 || strcasecmp($myrow['pay'], "CA") == 0) 
    && strcasecmp($myrow['linked'], "Y") == 0 
    && in_array($myrow['code'], array(200,302)) )
{
    echo "commercial";
} 
else
	echo "fail";


?>
are you doing anything other than the echo inside the if? If so, could you post that, it may be the problem...

Posted: Sun Jun 20, 2004 11:49 pm
by ChangingLINKS
Why did you test with

Code: Select all

<?php $myrow['pay'] = 'AB'; 
?>
?

For the code to work, it would have to pass with

Code: Select all

<?php $myrow['pay'] = 'CA'; 
?>
To answer your question, I am not doing anything but an echo.
The odd thing is that when I change BOTH to "CA" or just one to "CA"
it will not work.
I am having the same problem with another line (the same with L, and LA)
It *seems* like using 2 characters fails, and one character passes.

Posted: Mon Jun 21, 2004 12:02 am
by feyd
that was from the last test, to make sure it fails with something not expected.

Posted: Mon Jun 21, 2004 8:40 am
by ChangingLINKS
This issue has been resolved. The problem was that there was code above it that altered ['pay'] in such a way to make the query fail. In the future, I will post more code so that a solution can be found.