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
ChangingLINKS
Forum Newbie
Posts: 4 Joined: Sat Jun 19, 2004 4:11 pm
Post
by ChangingLINKS » Sat Jun 19, 2004 4:11 pm
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.
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Sat Jun 19, 2004 9:48 pm
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";
}
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Jun 19, 2004 10:09 pm
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Jun 19, 2004 10:25 pm
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 » Sun Jun 20, 2004 1:17 am
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jun 20, 2004 1:23 am
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 » Sun Jun 20, 2004 11:49 pm
Why did you test with
?
For the code to work, it would have to pass with
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jun 21, 2004 12:02 am
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 » Mon Jun 21, 2004 8:40 am
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.