0

Why is $row empty when I apply the while loop with mysql_fetch_assoc with an extra condition, but when the extra condition is not there, returns something, is this logical?

while ($row = mysql_fetch_assoc($result) 
        && $gen->getMailsSent() < 499) {
     //blah blah
}

In the above code, the compiler enteres the loop, but $row is empty

while ($row = mysql_fetch_assoc($result)) {
     //blah blah
} 

In this one, the compiler still enteres the loop, but then $row returns something, this to me i dont get and is not logical, can someone please explain why this occurs?

1
  • can you show the rest of your code? Can't tell much about it from that Commented May 28, 2013 at 8:06

3 Answers 3

3
while (($row = mysql_fetch_assoc($result))
        && $gen->getMailsSent() < 499) {
     //blah blah
}

Try this. Your problem is precedence - you actually tell it to

$row = (mysql_fetch_assoc($result) && $gen->getMailsSent() < 499)

See http://php.net/manual/en/language.operators.precedence.php

"&&" comes before "=" in the list, so it gets evaluated first.

Sign up to request clarification or add additional context in comments.

Comments

1

try

while (($row = mysql_fetch_assoc($result)) 
        && $gen->getMailsSent() < 499) {
     //blah blah
}

actually it shouldn't be empty, it should be a boolean.

Comments

0
Use while loop like this:

while (($row = mysql_fetch_assoc($result))  && ($gen->getMailsSent() < 499)) {
    code goes here..
}

hope this will help..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.