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 -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

What is happening when Matlab is starting a "parallel pool"? -