[SOLVED] One works, the other doesn't

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
ChangingLINKS
Forum Newbie
Posts: 4
Joined: Sat Jun 19, 2004 4:11 pm

[SOLVED] One works, the other doesn't

Post 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]
Last edited by ChangingLINKS on Mon Jun 21, 2004 9:54 am, edited 1 time in total.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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"; 
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

well.. the original works for me.. I don't know why it doesn't work for you..
ChangingLINKS
Forum Newbie
Posts: 4
Joined: Sat Jun 19, 2004 4:11 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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...
ChangingLINKS
Forum Newbie
Posts: 4
Joined: Sat Jun 19, 2004 4:11 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that was from the last test, to make sure it fails with something not expected.
ChangingLINKS
Forum Newbie
Posts: 4
Joined: Sat Jun 19, 2004 4:11 pm

Post 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.
Post Reply