chico1st Posted August 10, 2006 Share Posted August 10, 2006 I have a quick question, how do you make: coditional statement AND conditional statement so that both must be true?I have thisdo{}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 wrongTHANKS! Quote Link to comment https://forums.phpfreaks.com/topic/17084-and-very-quick/ Share on other sites More sharing options...
hostfreak Posted August 10, 2006 Share Posted August 10, 2006 Instead of and try: && Quote Link to comment https://forums.phpfreaks.com/topic/17084-and-very-quick/#findComment-72136 Share on other sites More sharing options...
corbin Posted August 10, 2006 Share Posted August 10, 2006 When ever I have 2 conditional statments i use ((condition 1) && (condition 2)) { } Quote Link to comment https://forums.phpfreaks.com/topic/17084-and-very-quick/#findComment-72137 Share on other sites More sharing options...
hitman6003 Posted August 10, 2006 Share Posted August 10, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/17084-and-very-quick/#findComment-72164 Share on other sites More sharing options...
hostfreak Posted August 10, 2006 Share Posted August 10, 2006 Isn't "&&" a bit more faster than "and"? I may have been mis-informed though. Quote Link to comment https://forums.phpfreaks.com/topic/17084-and-very-quick/#findComment-72166 Share on other sites More sharing options...
hitman6003 Posted August 10, 2006 Share Posted August 10, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/17084-and-very-quick/#findComment-72168 Share on other sites More sharing options...
corbin Posted August 10, 2006 Share Posted August 10, 2006 && over ranks AND if i remeber right... Also || over ranks OR... Quote Link to comment https://forums.phpfreaks.com/topic/17084-and-very-quick/#findComment-72169 Share on other sites More sharing options...
corbin Posted August 10, 2006 Share Posted August 10, 2006 Gah never mind... someone beat me to it :(:) Quote Link to comment https://forums.phpfreaks.com/topic/17084-and-very-quick/#findComment-72170 Share on other sites More sharing options...
chico1st Posted August 10, 2006 Author Share Posted August 10, 2006 okay is still doesnt work even with the proper brackets and using && .. i have discovered that it only uses the first conditional statement boldedhere is the code:do{...} while (([b]$row['caption'] != $fileCaption)[/b] && ($row['name'] != $fileName));thanks! Quote Link to comment https://forums.phpfreaks.com/topic/17084-and-very-quick/#findComment-72192 Share on other sites More sharing options...
hitman6003 Posted August 10, 2006 Share Posted August 10, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/17084-and-very-quick/#findComment-72195 Share on other sites More sharing options...
chico1st Posted August 10, 2006 Author Share Posted August 10, 2006 i dont know why but yours works and mine doesnt.. it baffles me but im not going to fight itthe reason i had the while was to shorten the #of loops, efficiency, but THANKS! Quote Link to comment https://forums.phpfreaks.com/topic/17084-and-very-quick/#findComment-72218 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.