How does this basic mySQL/PHP loop work?
September 9, 2010 4:13 PM Subscribe
Basic mySQL/PHP question. Help me understand how this simple while
loop involving mysqli_fetch_array() works.
posted by Ziggy Zaga to Computers & Internet (10 answers total) 1 user marked this as a favorite
I'm currently working through this book
and don't understand the mechanics behind a loop it's telling me to use.
$result = mysqli_query($link, 'SELECT joketext FROM joke');
while ($row = mysqli_fetch_array($result))
$jokes = $row['joketext'];
It is my understanding that mysqli_fetch_array() retrieves an array of results and stores it to $result. The next line grabs the current value of the 'joketext' column of $row and copies it to the $jokes array. I don't understand how this loop ever progresses though; there's no counter or anything. The code works though.
Why isn't this an infinite loop of writing the same value to the same location? There's nothing in the $jokes reference that indicates newer values should be stored to the location of x+1. What's going on here that I'm not seeing?