foreign key

A

Anonymous

Guest
I have 3 tables, the table of speaker has speaker ID, the table of workshop has ID but it has foreign key of speakerID and locationID, and table of location has locationID. I don't know how to use php to add those two foreign keys (speaker ID) and (locationID) into table of workshop?
It is easy to add records into a single table, they will be incremented automatically, but how to tell the foreign key in the table of workshop be matched automatically to the table of speaker and location? This is the always question that I am still doubting how do I make the foreign keys in the table of workshop to match up other two table(speaker and location). Does anyone knows about it? Thanks.

Beckmann
 
This is a SQL issue and not PHP.
Try this query out before you use it and make sure you get the right results:
Code:
SELECT workshop.ID,
workshop.some_other_field,
speaker.speakerID,
speaker.some_other_field,
location.locationID,
location.some_other_field 
FROM workshop LEFT JOIN speaker ON speaker.speakerID = workshop.speakerID 
LEFT JOIN location ON location.locationID = workshop.locationID;
Once every workshop has always a location and a speaker too, you can make this with WHERE clause only. LEFT JOIN's are good when this preposition is false.
 
gesf said:
This is a SQL issue and not PHP.
Try this query out before you use it and make sure you get the right results:
Code:
SELECT workshop.ID,
workshop.some_other_field,
speaker.speakerID,
speaker.some_other_field,
location.locationID,
location.some_other_field 
FROM workshop LEFT JOIN speaker ON speaker.speakerID = workshop.speakerID 
LEFT JOIN location ON location.locationID = workshop.locationID;
Once every workshop has always a location and a speaker too, you can make this with WHERE clause only. LEFT JOIN's are good when this preposition is false.

I make a pulldownmenu of the listed name of other 2 tables for selecting them purpose once I add a foreign key in the workshop page , but how the php code is triggering the pulldown list for matching other 2 tables ID?

Thanks
 
Back
Top