you have this query:
you need to modify it to join to the grade table:Code:SELECT Name FROM courses
you can remove the line breaks -- that just made it easier to read. $studentID is a variable that you should create from $_GET['student'] (with mysql_real_escape_string(), because we're also sending raw user input to the database otherwise):Code:SELECT c.Name FROM Grade g LEFT JOIN Courses c ON c.CourseID=g.CourseID WHERE g.StudentID={$studentID}
you may notice, however, that if you view your subjects.php script without a query string set, that you could get a warning/notice that $_GET['student'] doesn't exist. we can do simple validation when defining this variable then:Code:$studentID = mysql_real_escape_string($_GET['student']);
this is essentially the shorthand equivalent of the following:Code:$studentID = isset($_GET['student']) ? $_GET['student'] : 0;
whichever you use doesn't matter. then, your query will run with a studentID of 0 (which will most likely never exist), and just won't return any results. you could also display some sort of error message.Code:if(isset($_GET['student'])){ $studentID = $_GET['student']; }else{ $studentID = 0; }
because 0 evaluates to false in PHP, we don't need to explicitly check if $studentID is equal to zero ($studentID == 0), and instead we can just check if $studentID evaluates to false (!$studentID).Code:if(!$studentID){ echo "You didn't pick a student."; }else{ // the rest of your script would basically go here }
hope that made some sense.




Reply With Quote