0

Problem

While I am fetching information from mysql, I also want to check that some specify column in mysql row is 0.

But then I get the notice Undefined Variabe yet the code works?

Code Line 157:

        while($row = $fetch->fetch( PDO::FETCH_ASSOC  ) && $row['status'] == 0) {

Error I get

Notice: Undefined variable: row in C:\xampp\htdocs\recover\admin\index.php on line 157

My question:

How do I get rid of that error without creating a if statement under the while loop? I basically want it to handle this in the while loop, if I am not doing that wrong?.

Is using a if statement under the while loop better than using it in the while loop?

What is causing the error? I am already defining what $row is before the && row['status'] == 0.

Thanks

1
  • before the while loop assign null to $row Commented Mar 30, 2013 at 20:21

1 Answer 1

3

You need parentheses:

while(($row = $fetch->fetch( PDO::FETCH_ASSOC  )) && $row['status'] == 0)
Sign up to request clarification or add additional context in comments.

2 Comments

Oh I get this now.. Thanks a lot!
Another possibility is to replace && with and, it has other precedence rules. (Although parentheses are much clearer and I always use them around assignments in statements, but that's because of modern C compiler rules which don't apply here)

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.