Jump to content


Photo

AND/OR


  • Please log in to reply
2 replies to this topic

#1 breadnbutter

breadnbutter
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 29 April 2006 - 04:34 PM

I'm pretty new to PHP. I have done a few pages of code, and I'm now starting to get my head round it. However, I've looked on php.net and can't find the right syntax for an 'AND' or and 'OR' statement, a bit like in SQL. Is there such a thing?

Here is the context I want to use it in.

$areab = ($_POST['county']);

if ($areab == "Cambridgeshire")
{echo "E Anglia";} else {echo "";}

This is going to be part of a much more complex bit of code, but |I am using the echo to test to see if this state ment works. Which is does. But what I want to do is

$areab = ($_POST['county']);

if ($areab == ("Cambridgeshire") OR ("Suffolk") OR ("Norfolk")
{echo "E Anglia";} else {echo "";}

but this doesn't work, what is it that I should be doing?

#2 breadnbutter

breadnbutter
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 29 April 2006 - 05:34 PM

Sorted it by setting up an array....




#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 29 April 2006 - 05:53 PM

well just for future reference, it would look like this:

if (($areab == "Cambridgeshire" OR ($areab=="Suffolk") OR ($areab=="Norfolk"))
{echo "E Anglia";} else {echo "";}

you can also use || instead of OR
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users