#1 code
$row = $result->fetch_assoc());
while ($row) {
// code here
}
#2 code
while ($row = $result->fetch_assoc());) {
// code here
}
Why #1 code and #2 code give different result?
#1 code
$row = $result->fetch_assoc());
while ($row) {
// code here
}
#2 code
while ($row = $result->fetch_assoc());) {
// code here
}
Why #1 code and #2 code give different result?
Because in #1 you execute fetch_assoc()
only once, while in #2 you execute it on every loop iteration.
In other words, in #2 fetch_assoc()
will keep on returning rows as long as there are rows available in the result set. #1 will enter an infinite loop if there is at least one row available.