While loop is over my head
View Single Post
08-31-2009, 01:55 PM
Join Date: Sep 2007
Originally Posted by
That helps...I'm still trying to get the full hang of this concept.
while($row = mysql_fetch_assoc($result))
1. The variable $row will be assigned the value(s) of the array of the first row of the results of the db query (assuming the query was successful).
2. Do everything within the WHILE loop. Drop the pointer to the second row in the db query results.
3. If there is another row in the db query results, then $row will take the second row's array value and repeat the WHILE loop.
4. And on and on, until the pointer is passed the last row of the db query resultset, at which point $row will not contain a value, and the WHILE loop exits.
Does that sound about right for the WHILE loop statement?
1 and 2. Mysql_fetch_assoc returns a single row returned from the query as an array. It can keep track of itself and keep submitting the next row every time its called.
3. Yes, but not in your script since it returns before the loop can repeat.
4. Almost, I believe that the results are passed by value. But other that that, you are correct.
The Following User Says Thank You to Village Idiot For This Useful Post:
View Public Profile
Send a private message to Village Idiot
Find More Posts by Village Idiot