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 -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -