Jump to content


Photo

AND? very quick


  • Please log in to reply
10 replies to this topic

#1 chico1st

chico1st
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 10 August 2006 - 12:15 AM

I have a quick question, how do you make: coditional statement AND conditional statement so that both must be true?

I have this
do{
}while ($row['caption'] != $fileCaption) and $row['type'] != $fileType and $row['size'] != $fileSize and $row['caption'] != $fileCaption);

with just teh first conditinal statement it works but if I add more it doesnt. I think my "and" thing is wrong
THANKS!

#2 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 10 August 2006 - 12:17 AM

Instead of and try:

&&

#3 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 10 August 2006 - 12:19 AM

When ever I have 2 conditional statments i use
((condition 1) && (condition 2)) {  }
Why doesn't anyone ever say hi, hey, or whad up world?

#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 10 August 2006 - 12:52 AM

Your parenthesis are wrong"

while (($row['caption'] != $fileCaption) and ($row['type'] != $fileType) and ($row['size'] != $fileSize) and ($row['caption'] != $fileCaption))

Using && or "and" makes little difference execpt in a very few, very specific situations.

#5 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 10 August 2006 - 12:53 AM

Isn't "&&" a bit more faster than "and"? I may have been mis-informed though.

#6 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 10 August 2006 - 12:56 AM

Speed wise they are exactly the same.  Their precedence is different.  && is slightly higher than "and".  See here:

http://us3.php.net/m...tors.precedence

#7 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 10 August 2006 - 12:56 AM

&& over ranks AND if i remeber right... Also || over ranks OR...
Why doesn't anyone ever say hi, hey, or whad up world?

#8 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 10 August 2006 - 12:57 AM

Gah never mind... someone beat me to it :(:)
Why doesn't anyone ever say hi, hey, or whad up world?

#9 chico1st

chico1st
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 10 August 2006 - 01:26 AM

okay is still doesnt work even with the proper brackets and using && .. i have discovered that it only uses the first conditional statement bolded

here is the code:
do{
...
} while (($row['caption'] != $fileCaption) && ($row['name'] != $fileName));
thanks!

#10 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 10 August 2006 - 01:30 AM

Why not use an if statement inside of your while loop?

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  if (($row['caption'] != $fileCaption) && ($row['name'] != $fileName)) {
    ... whatever ...
  }
}


#11 chico1st

chico1st
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 10 August 2006 - 02:01 AM

i dont know why but yours works and mine doesnt.. it baffles me but im not going to fight it
the reason i had the while was to shorten the #of loops, efficiency, but THANKS!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users