In the tutorial on accessing MySQL tables in PHP, they gave the code to list all values as:
$query = "SELECT * FROM example";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo $row['name']. " - ". $row['age'];
echo "<br />";
}
I understand how the while loop returns true when there is a row to print out and false when there are no more, but I don't understand why it doesn't work if I write:
$query = "SELECT * FROM example";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
while($row){
echo $row['name']. " - ". $row['age'];
echo "<br />";
}
It just returns the first row, I assume this means it is always returning the value as true but I don't understand why.