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

string - Using python and postgres, variables within execute function? -

android - How to get the Uri path from a ImageView? -