PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
This looks like the same project you were working on in another thread.
In this case, you wouldn't want any column to be a unique column. that would cause problems where a module could only have one course or a course could only have one module. I may be missunderstanding what you're trying to do, but let me take a shot at it.
You could have three tables:
Modules
----------
module_id
module_name
Course
----------
course_id
course_name
CourseModules (none of the fields below should be unique or a primary key) you could index them for speed though.
----------
module_id
course_id
then if you wanted to have course #2 have a module #3, you would do an
insert into CourseModules (module_id, course_id) values (3,2);
then if you wanted to check and see if module #3 was already associated with course #2, you would do a select on it first.
$result=mysql_query("select * from CourseModules where module_id=3 and course_id=2;");
if (mysql_num_rows($result) > 0)
{
echo "course 2 is linked to module 3";
// you could even do and update here if you wish.
}
else
{
// if it's not found, you can go ahead and add it with an insert if you wish.
insert into CourseModules (module_id, course_id) values (3,2);
}