Thanks for the advice timothybard. The master-id thing came from a PHP MySQL database example for an address book that I found in Sam’s Teach Yourself PHP, MySQL and Apache, which seemed to have some elements that behaved somewhat like I am looking for in this project. Clearly I don’t know much about this stuff however I have six books on the table here beside me as I try to pick up some knowledge on the subject.
I think that the way that the address book PHP works is to insert the name of the person into the table and then extract it again using a piece of code that looks like this:
master-id = mysql_inseret_id ( );
which is then used in other tables. What I am getting from your advice is that I don’t really need this field but instead can rely on the foreign key to make the associations.
I confess that I don’t fully understand your suggested design using a session, so I will ramble on in the direction that I was headed and maybe you will be able to extract enough information to get me on track.
I did consider using something like a “session” or an “activity event” as the core to all of this and I’m thinking that this is what you are pointing me toward. I opted to see if I couldn’t make it work with just the 4 tables. As stated this project is simply something that has the potential to improve significantly on a spreadsheet application that is currently used, and my interest is more in gathering some knowledge about databases and PHP (or something similar) than coming up with the most eloquent solution, so I am delighted to try a few things that might contribute to my education. And I have the luxury of lots of time. It is always more interesting for me to work on something that has a direct application in my world than exclusively textbook examples.
On further reflection, I decided to add two more fields. The first would be a field called “status” in the “person” table that would serve to indicate whether the member was current or lapsed. The other additional field would be a “comments” field that would live in the “activities” table. I’m not sure if this would actually get a lot of use, however it just seems like a good idea at the time.
Considering the relationship between the tables, here is what I came up with;
A person can participate in many activities and any activity could be attended by many persons. Therefore it is a many-to-many relationship requiring an association table.
A “category” can have many activities, however an activity can only belong to one category, hence a one to many relationship.
The “date and time” issue does perplex me. I am going with the idea that a date may include many activities and that an activity may be repeated on many dates so a many-to-many relationship with an association table.
Here is what the table and field design might look like then:
person: - id (primary key), master_id, first_name, last_name, status
category: - id (primary key), master_id (foreign key), category_name
activity: - id (primary key), master_id (foreign key), activity_name, comments
date_time: - id (primary key), master_id (foreign key), date, time
On to what I gather is the next phase or normalization. My take on it is that the 1st normal form conditions are satisfied. As for the 2nd normal form, this is getting a little blurry, but I think that the above complies as does the 3rd normal form, which isn’t quite so blurry.
So to summarize, I would be happy to use your ideas, since they are undoubtedly much better than mine, given the distinct lack of exposure to the subject, but it does beg the question “Would what I have got going here actually work, albeit crudely?” or would it flop.
My thanks also to “almostbob” for his comments. Performance isn’t really an issue for this particular application. There will not be a huge number of records in the database for a long while, and the number of users will be limited to a handful of interested parties who will simply print off reports. That brings up another subject, but at the pace that I am going, it could be a while before I get to that.
Thanks to all,
Sheila