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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.