PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm having some problems with this while loop. When I run this query from my MYSQL console for #506 I get 3 rows in set but this code only returns result #2 & #3. What am I doing wrong?
Many thanks in advance
-J
<?php
$student_ensemble_query="SELECT e.ensemble_description
FROM ensemble AS e
JOIN ensemble_student AS es ON e.ensemble_ID = es.ensemble_ID
WHERE es.student_ID = 506;";
$ensemble_detail=mysql_query($student_ensemble_query) or die("Josh sucks at SQL and query failed with error: ".mysql_error());
$info = mysql_fetch_array($ensemble_detail);
mysql_close();
?>
<?php
while($info = mysql_fetch_array($ensemble_detail))
{
echo "".$info['ensemble_description']. "<br>" ;
}
?>
Is fetching the first row out of the result, so the one in the loop starts with the second one.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
move mysql_close() to the end of the file (after the while-loop) and remove the $info = mysql_fetch_array($ensemble_detail); expression. Then you should get what you expected.