Forum Moderators: coopster

Message Too Old, No Replies

Did I get OR correct?

         

JAB Creations

9:33 pm on Apr 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just want to know if I properly said if cookie bandwidth = 1 or 2 do this...

if ($HTTP_COOKIE_VARS[bandwidth]=="1"¦¦"2") {};

sned

9:36 pm on Apr 7, 2005 (gmt 0)

10+ Year Member



Actually, it should look like this:

if($HTTP_COOKIE_VARS[bandwidth]=="1"¦¦$HTTP_COOKIE_VARS[bandwidth]=="2") {};

-Sned

[oops, edited . the []

JAB Creations

11:24 pm on Apr 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well it works! The only thing is I think my way would make more sense if you're just saying this value or that. But hey it works and it's not bandwidth so I don't care. :-J

Oh thanks btw! :-)

ergophobe

9:29 pm on Apr 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Actually, no, your method wouldn't make more sense for the following reason.

Let's say that I'm going to let people see my page if they are 'friendly' but not if they are 'troublemakers' and I set a flag

$troublemaker = 1;

if ($username!= 'ergophobe' &&!$troublemaker)
{
Let them in.
}

What do you mean to do there? Keep ergophobe out and any other user who is a troublemaker? Or keep out any user with the name 'ergophobe' or with the name '1'

your method would result in the latter case, but you probably want the former.

JAB Creations

9:54 pm on Apr 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey ergophobe...

Actually my cookie has 4 settings...

1 = Dialup / No Audio
2 = Dialup / Yes Audio
3 = Broadband / No Audio
4 = Broadband / Yes Audio

I guess it makes more sense when you know there is more then two choices :-D

Your point makes sense though if I only had two choices.

dreamcatcher

9:23 am on Apr 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can use in_array if you want to keep things tidier:


$options = array(1,2,3,4);

if (in_array($HTTP_COOKIE_VARS[bandwidth],$options))
{
//ok, do something
}
else
{
//not ok
}

dc

ergophobe

3:27 pm on Apr 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Actually, my point is that your way is logically ambiguous and programming languages can't handle ambiguous very well. It's not really a matter of the number of choices.