Lets assume that you have a table student
with following data
id name
1 JD
2 Dev
3 Pallavi
Now if your $query = "SELECT * FROM student"
CASE: 1
while($row = mysql_fetch_array(mysql_query($query))) { ... }
For the first iteration the execution will be
- mysql_query($query)
- mysql_fetch_array(get_array_obtined_from_first_step)
- Assign the current row to $row
In first step you get all 3 records of the student table. Then you fetch the Record Set in 3rd step you assign the row to $row.
Now as your 3 statements are in the while loop's condition, it will always be TRUE, because it will execute your query each time the loop is iterated, executing all the statements, making it infinite loop.
CASE: 2
$query = mysql_query($query);
while($row = mysql_fetch_array($query)){}
Here the query is executed ONCE and then each time the cursor is incremented assigning a single row to $row till the end of Result Set.
Thus when the end of Result Set is achieved it stops.