I am not sure if your question is one of:
a) object theory
b) database design
c) php implementation
THEORY
o "Student" is an object
o "Course Grade" is an object
o "Student" has many course grades
DATABASE
Student Table
-- s_student_id
-- s_student_name
Course Table
-- c_course_id
-- c_course_name
Grade Table
-- g_student_id
-- g_course_id
-- g_course_grade
PHP Implementation
<?php
class CourseGrade
{
var $course_id;
var $course_name;
var $course_grade;
function CourseGrade($student_id, $course_id) {
$sql = "select * from grade a, course b where a.student_id = ".$student_id." and a.course_id = ".$course_id." and a.course_id = b.course_id";
// execute sql and put result set in $data variable then...
$this->course_id = $data->c_course_id;
$this->course_name = $data->c_course_name;
$this->course_grade = $data->g_course_grade;
}
} // end class
class Student
{
var $student_id;
var $student_name;
var $student_grades = array();
function Student($id) {
$sql = select * from student where s_student_id = ".$id;
// execute sql to get student info from table and put into $data
// then...
$this->student_id = $id;
$this->student_name = $data->s_student_name;
$sql = "select g_student_id, g_course_id from grade where g_student_id = ".$id;
// execute sql to get result set and put into $data. Then...
while ($data) {
$this->student_grades[] = new CourseGrade($data->g_student_id, $data->g_course_id);
}
} // end function
} // end class
// instantiate a student object for student number 105
$myStudent = new $student(105);
// now lets access some of the properties of the student object
print $myStudent->student_id;
print $myStudent->student_name;
// well that is straight forward, but what about those grades?
// this loop will print out all the grades for the student...
$numgrades = count($myStudent->student_grades);
for ($idx=0, $idx<$numgrades, ++$idx) {
$grade = $myStudent->student_grades[$idx];
print $grade->course_name." === ".$grade->course_grade."<br>\n";
}
?>
It's a rough example. There may be typos and the sql execution is left out, but I think you can see where even in a one_to_many relationship the many can be properties of the one.
HTH
-- Rich Rijnders
-- Irvine, CA US