1

Please have a look at this code snippet -

while ($row = $getForums_data->fetchAll(PDO::FETCH_ASSOC)) {

I've tried different variations of the above but it keeps putting me in the loop of death. Can anybody tell what is wrong here? The query isn't wrong because I tested it and it works fine. But the while loop doesn't end.

2
  • use $getForums_data->fetch Commented Apr 3, 2016 at 7:43
  • Where did you see that you have to use a while loop with fetchAll()? The manual surely doesn't state that. Did you read the function synopsis in the manual at all? Commented Apr 3, 2016 at 9:47

1 Answer 1

3

fetchAll() fetches all rows from your result set so if there are results, it will return a non-empty array each time you call it.

If you just want to get the results row-by-row until there are no more (and the loop stops...), you need:

while ($row = $getForums_data->fetch(PDO::FETCH_ASSOC)) {

Or you fetch all rows into a variable and use a foreach() to loop over that variable.

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

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.