Jump to content

Archived

This topic is now archived and is closed to further replies.

chico1st

AND? very quick

Recommended Posts

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!

Share this post


Link to post
Share on other sites
When ever I have 2 conditional statments i use
((condition 1) && (condition 2)) {  }

Share this post


Link to post
Share on other sites
Your parenthesis are wrong"

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

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

Share this post


Link to post
Share on other sites
Speed wise they are exactly the same.  Their precedence is different.  && is slightly higher than "and".  See here:

http://us3.php.net/manual/en/language.operators.php#language.operators.precedence

Share this post


Link to post
Share on other sites
&& over ranks AND if i remeber right... Also || over ranks OR...

Share this post


Link to post
Share on other sites
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 (([b]$row['caption'] != $fileCaption)[/b] && ($row['name'] != $fileName));
thanks!

Share this post


Link to post
Share on other sites
Why not use an if statement inside of your while loop?

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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.