I am building a simple website that helps students and instructors in universities.
I am facing a problem about the following query:
An instructor retrieves the students’ IDs and names who are enrolled in the course he/she teaches.
I have the following tables, followed by their fields:
Enrollment (CourseCode – StudentID – Grade)
Studnet (ID – Name)
As you can see the only connector between the two tables is the student ID.
The code that I wrote is
<?
session_start();
$COCODE = $_SESSION['GlobalCode'];
$result11 = mysql_query("SELECT * FROM Enrollment WHERE CourseCode = '$COCODE' ") ;
$row11 = mysql_fetch_array($result11);
$StID = $row11['StudentID'];
$result22 = mysql_query("SELECT * FROM Student where StudentID= '$StID' ") ;
echo "<table border cellpadding=3>";
while($row123 = mysql_fetch_array($result22))
{
echo "<tr>";
echo "<td>".$row123['ID']."</td> ";
echo "<td>".$row123['Name']."</td> ";
echo "</tr>";
}
echo "</table>";
?>
What I am trying to do is to retrieve the course code from the Enrollment table and then retrieving the students names through the ID.
The problem is that I got the following message:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
I hope you can help me solving the problem.
Thanks
Have you tried to narrow down which of the queries is causing the problem? That would be your first step. Some other pointers:
you need to check that each SQL query is successful and returning a valid value before using it in the next query… otherwise that query will cause an error.
Try using:
mysql_query ($your_query) or die ('Error: '.mysql_error ());for each query for a more detailed error message. (for debugging only, not for production)