Re: Foreign Keys Question
| From: | Robert Cummings | Date: | Thu, 11 Dec 2008 18:55:39 +0000 |
| Subject: | Re: Foreign Keys Question | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-284493@lists.php.net to get a copy of this message | ||
On Thu, 2008-12-11 at 13:46 -0500, tedd wrote:
> At 12:29 PM -0600 12/11/08, phphelp -- kbk wrote:
> >Hey tedd ---
> >
> >Do I understand your structure correctly that you have something like:
> >
> >Courses (table)
> >course_id,
> >subject_id,
> >student1_id,
> >student2_id,
> >student3_id,
> >student4_id,
> ><etc.>
> >
> >Is that right?
> >
> >Ken
>
> Ken:
>
> That was right, but I think I've reconsidered.
>
> You see, Richard pointed out the error of my ways, namely:
>
> Student table has student data and ID -- as may records as there are students.
>
> Instructor table has instructor data and ID -- as may records as
> there are instructors.
>
> Course table has course data, ID and Instructor ID and Student ID --
> but the number of records vary.
>
> While there will be only one record per Instructor and one pre
> Student, the Course table can have up to four records for each course
> depending upon actuall attendance.
>
> I think that makes more sense.
Student attendance should be a table with rows for each student in
attendance. If you want to limit the number make a check before adding
another student. Don't hard code the number via fields like above or
you'll find it overly ugly to add/remove students or even increase the
number of allowed students. As it stands to allow 6 students you would
have to add 2 more columns. With attendance controled by a table with a
row for ewach attendance you would only need to update a configuration
variable the determines the maximim number of allowed students in
attendance.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP