Jump to content

help with mysql statement


husslela03

Recommended Posts

i'm having trouble returning a result for mySQL statement i have:

 

$sql2=mysql_query("SELECT * FROM assignments, courses LEFT JOIN assignments ON (courses.courseID = assignments.courseID) LEFT JOIN grades ON (assignments.assignmentID = grades.assignmentID) WHERE (grades.userID='$userID' AND assignments.courseID='$courseName')");

 

I want to find all the grades in the grades table partaining to the student and the class chosen

 

Here are my table structures

 

Courses table:

courseID courseName

1 Class A

        2 Class B

 

Assignments table:

assignmentID courseID assignmentName assignmentMaxValue assignmentWeight

1               1     Homework1                         100                       10

2               1     Homework2                         100                       10

 

Grades table

gradeID userID assignmentID score

1   1                   3           96

2   2                   3           85

 

The userID for the student is carried in the session along with the courseID

 

Any help would be appreciated with my mySQL statement

 

So i want to find all the grades for the student for the matching courseID.

Link to comment
https://forums.phpfreaks.com/topic/198708-help-with-mysql-statement/
Share on other sites

I think this is your problem:

 

courseID='$courseName'

 

courseName=$courseName

 

and:

remove the assignment after FROM:

$sql2=mysql_query("SELECT grades.* FROM courses LEFT JOIN assignments USING (courseID) LEFT JOIN grades ON (assignments.assignmentID = grades.assignmentID) WHERE (grades.userID='$userID' AND assignments.courseName='$courseName')");

 

Unless $courseName was set to the course id.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.