php - why fetch_assoc work on while? -


#1 code

$row = $result->fetch_assoc()); while ($row) { // code here } 

#2 code

while ($row = $result->fetch_assoc());) { // code here } 

why #1 code , #2 code give different result?

because in #1 execute fetch_assoc() once, while in #2 execute on every loop iteration.

in other words, in #2 fetch_assoc() keep on returning rows long there rows available in result set. #1 enter infinite loop if there @ least 1 row available.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -