Need help with an if...else statement

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
Njacobi
Forum Newbie
Posts: 3
Joined: Mon Jun 09, 2008 7:33 pm

Need help with an if...else statement

Post by Njacobi »

Thanks for the help on this. New to PHP and this should be a basic question, what I need is:

if ($input1=='logix') and ($input2=='desk')
{
echo "<p>You want $nba1</p>";
}

So if 1 = this and 2 = that, you want 3.

Thanks for the help!
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: Need help with an if...else statement

Post by panic! »

Code: Select all

 
if ($input1=='logix' && $input2=='desk')
{
echo "<p>You want $nba1</p>";
}
 
dbemowsk
Forum Commoner
Posts: 82
Joined: Wed May 14, 2008 10:30 pm

Re: Need help with an if...else statement

Post by dbemowsk »

I don't get the question.
Njacobi
Forum Newbie
Posts: 3
Joined: Mon Jun 09, 2008 7:33 pm

Re: Need help with an if...else statement

Post by Njacobi »

panic! wrote:

Code: Select all

 
if ($input1=='logix' && $input2=='desk')
{
echo "<p>You want $nba1</p>";
}
 
Thanks, I'll give it a try, seems to be what I'm looking for. THANKS again! :drunk:

*EDIT* Just tried it out, does exactly what I wanted, BIG THANKS
dbemowsk
Forum Commoner
Posts: 82
Joined: Wed May 14, 2008 10:30 pm

Re: Need help with an if...else statement

Post by dbemowsk »

I am confused. That is the code that was in your original post.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Need help with an if...else statement

Post by VladSun »

dbemowsk wrote:I am confused. That is the code that was in your original post.

Code: Select all

if ($input1=='logix' and $input2=='desk')
!=

Code: Select all

if ($input1=='logix') and ($input2=='desk')
The second one has wrong PHP syntax.

@Njacobi
AND is a PHP keyword. It is logically the same as && but has different operator precedence:
http://phpbuilder.com/manual/en/languag ... precedence
There are 10 types of people in this world, those who understand binary and those who don't
Njacobi
Forum Newbie
Posts: 3
Joined: Mon Jun 09, 2008 7:33 pm

Re: Need help with an if...else statement

Post by Njacobi »

Yeah, originally I put in 'and' just because that's what I wanted it to mean. Didn't think it would actually work. To make it work, all I had to do was get rid of the extra parentheses. Thanks again to everyone who helped. The script is finished and works great.
dbemowsk
Forum Commoner
Posts: 82
Joined: Wed May 14, 2008 10:30 pm

Re: Need help with an if...else statement

Post by dbemowsk »

I see that now that I looked closer.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Need help with an if...else statement

Post by califdon »

dbemowsk wrote:I see that now that I looked closer.
's Okay. I can recommend a good ophthalmologist for you. :lol:
Post Reply