Jump to content


Photo

will OR , && work


  • Please log in to reply
13 replies to this topic

#1 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 06 August 2006 - 01:51 PM

umm i want to check if the user visiting the page has 2 character
1 male/trans
1 female/trans
and only continue if the user owns one of those character
<?php if ($char1 == "Male" && $char2 == "Female" OR $char1  == "Male" && $char2 == "Trans" OR $char1 == "Female" && $char2 == "Male" OR $char1 == "Female" && $char2 == "Trans" OR $char1 == "Trans" && $char2 == "Male" OR $char1 == "Trans" && $char2 == "Female" OR $char1 == "Trans" && $char2 == "Trans") 
{
echo"You have a pair.";
}
?>

will this work?

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 06 August 2006 - 01:58 PM

i want to check if the user visiting the page has 2 character ... and continue if the user owns one of those character


That's less than clear. Care to elaborate?
Legend has it that reading the manual never killed anyone.
My site

#3 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 06 August 2006 - 02:00 PM

It should works.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#4 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 06 August 2006 - 02:01 PM

you need extra braces i beleave

<?php if (($char1 == "Male" && $char2 == "Female") OR ($char1  == "Male" && $char2 == "Trans") OR ($char1 == "Female" && $char2 == "Male") OR ($char1 == "Female" && $char2 == "Trans") OR ($char1 == "Trans" && $char2 == "Male") OR ($char1 == "Trans" && $char2 == "Female") OR ($char1 == "Trans" && $char2 == "Trans")) 
{
echo"You have a pair.";
}
?>

AndyB I think that he has some kinda game script or sumet and he wants to check if they have 2 diffrent variables selected which means they make up a pair..

Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#5 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 06 August 2006 - 02:02 PM

lol sorry if i wasnt clear enough i just wanted to make sure that "OR" works in php not only querys.But it does work thanx

#6 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 06 August 2006 - 02:07 PM

|| also works as an OR
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#7 ignace

ignace
  • Moderators
  • Now mod flavored
  • 6,431 posts
  • LocationBelgium

Posted 06 August 2006 - 02:10 PM

OR is the same as ||, AND is the same as &&, bitwise or (|) bitwise and (&)

P.S.: can someone tell me what the & does when used in one of the following ways:

$Var &= $Var2; // object or something?
function myfunction(&$var); // Here, i believe you need to provide an already declared variable

if you know also otherways the & can be used, please let me know..

#8 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 06 August 2006 - 02:31 PM

When used thus: "myfunction(&$var);" you are passing a reference to the variable, not a copy of it.  Which means that if the function alters the value, the original variable gets altered and stays altered after the function returns, rather than a copy of the variable being altered and then thrown away when the function returns.

I guess "$var &= $var2" would logically and the values and stored the result in $var, so if they were 195 (binary 11000011) and 144 (binary 10001000) the result would be 128 (binary 10000000) but I've never used it in PHP (and seldom in C).
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#9 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 06 August 2006 - 02:38 PM

Sample "bitwise and"

<?php
$var1 = 7;
$var2 = 3;

echo '<pre>';
printf ('%08s<br>%08s', decbin($var1), decbin($var2) );
echo '</pre>';

$var1 &= $var2;

echo "7 &amp; 3 = $var1";
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#10 ignace

ignace
  • Moderators
  • Now mod flavored
  • 6,431 posts
  • LocationBelgium

Posted 06 August 2006 - 02:47 PM

@Barand echo "7 &amp; 3 = $var1"; // Gives 3 right?

#11 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 06 August 2006 - 02:49 PM

Yes. If you run the snippet you get
[pre]00000111
00000011
7 & 3 = 3[/pre]
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#12 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 06 August 2006 - 02:49 PM

Should do.

Once you get your head around this binary malarky you can say to people things like "I'll be with you in 3 or 4 minutes" and what they don't realize is that actually gives you seven minutes.....
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#13 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 06 August 2006 - 03:01 PM

Converstional language is very lax when it comes to logic. People often specify something like "The query should select two records, where the id is 1 and the id is 2"
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#14 ignace

ignace
  • Moderators
  • Now mod flavored
  • 6,431 posts
  • LocationBelgium

Posted 06 August 2006 - 03:02 PM

yeah, the only problem is my native language is dutch, so i can not use the bitwise or, and it would look silly, when your suddenly start talking english ;D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users