...All help welcome!? I took the code below from a PHP book I'm reading and I understand how it all works except 1 point that confuses me a little - I don't get how the line "while ($rows=mysql_fetch_array($results))" works. At the point in the program that $rows is tested as to whether it is equal to the recordset which is mysql_fetch_array($results), there is surely nothing in $rows yet as nothing has been assigned to it yet so how is this condition satisfied?
Also, mysql_fetch_array obviously takes only one record from the recordset "$results" but does it automatically move to the next record in $results with every iteration of this loop?
<?php
//connect to MySQL
$connect = mysql_connect("host", "user", "password") or
die ("Hey loser, check your server connection.");
//make sure we're using the right database
mysql_select_db ("database");
$query="SELECT movie_name, movie_type
FROM movie
WHERE movie_year>1990
ORDER BY movie_type";
$results=mysql_query($query)
or die(mysql_error());
while ($rows=mysql_fetch_array($results)) {
extract($rows);
echo $movie_name;
echo " - ";
echo $movie_type;
echo "<br>";
}
?>
Also, mysql_fetch_array obviously takes only one record from the recordset "$results" but does it automatically move to the next record in $results with every iteration of this loop?
<?php
//connect to MySQL
$connect = mysql_connect("host", "user", "password") or
die ("Hey loser, check your server connection.");
//make sure we're using the right database
mysql_select_db ("database");
$query="SELECT movie_name, movie_type
FROM movie
WHERE movie_year>1990
ORDER BY movie_type";
$results=mysql_query($query)
or die(mysql_error());
while ($rows=mysql_fetch_array($results)) {
extract($rows);
echo $movie_name;
echo " - ";
echo $movie_type;
echo "<br>";
}
?>