I have this exact situation, but with no PHP MySQL code to
read so I can figure out what to do (how to write the code for
these 3 tables). I'm a beginner, self-taught, and I've been working
on this for months, with no success. I've purchased and read (and
worked through) PHP for Dreamweaver 8 by Dave Powers, but this
isn't covered in there:
CREATE TABLE students (
student_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(50) NOT NULL DEFAULT '',
lastname VARCHAR(50) NOT NULL DEFAULT '',
sex ENUM('M','F') NOT NULL DEFAULT 'M',
dob DATE NOT NULL DEFAULT '0000-00-00'
CREATE TABLE classes (
class_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, instructor_id INT(11) NOT NULL DEFAULT '0',
name VARCHAR(50) NOT NULL DEFAULT '',
hours INT(1) NOT NULL DEFAULT '0'
CREATE TABLE students_classes (
student_id INT(11) NOT NULL DEFAULT '0', class_id INT(11) NOT NULL DEFAULT '0', semester ENUM('FALL','SPRING','SUMMER') NOT NULL DEFAULT
year INT(4) NOT NULL DEFAULT '2005',
grade INT(1) DEFAULT NULL,
PRIMARY KEY (student_id,class_id,semester,year)
My thinking might be illogical since I don't understand how
(students_classes.student_id) receives its value from |students|,
while maintaining a NOT NULL value in (students_classes.class_id).
How does a value from a field in |students| or |classes| get into
|students_classes| without violating the NOT NULL conditions of one
of its fields?
Please, help me with this. I'm sinking deeper into
agoraphobia over this. :)
Thank you for your consideration.
Newsgroup_User, Nov 21, 2006 1:53 AM
> How does a value
> from a field in |students| or |classes| get into
> violating the NOT NULL conditions of one of its fields?
I don't understand what you mean by "without violating the
conditions". Basically, you have to insert the student_id and
into students_classes when you're creating a new record. In
and update record forms, you need to have two drop-down
menus: one for
the student's name, the other for the class name. Store the
as the value for each <option> in the first one, and
the class_id in the
Since you have worked through "Foundation PHP for Dreamweaver
you), you build these drop-downs in the same way as for the
You're brilliant! I have no idea if what you suggested in
your reply indeed works, as, I found a solution, somehow, (or was
it a work-around?). Anyway, I just wanted to thank you for that
Foundations book! It's my bible! And for that, I say, "You're
> You're brilliant! I have no idea if what you suggested
in your reply indeed
> works, as, I found a solution, somehow, (or was it a
work-around?). Anyway, I
> just wanted to thank you for that Foundations book! It's
my bible! And for
> that, I say, "You're brilliant"!
> Thank you!
Thank *you*. I've been trying to tell people for years that
brilliant, but they take no notice. Finally, I've found
Seriously, though, I'm glad you found the book useful. Now
all I need to
do is to convince another few thousand to break open their
buy a copy.