dgruetter Posted February 10, 2012 Share Posted February 10, 2012 Hi. I am trying to restructure my PHP code into oop structure and now have developed an extended class called "vendor_user" from a base class "user." The basic attributes in "User" will be id, email, password. The extended class "vendor_user" will have vendor_id, info, phone_num, tagline, etc.. I was going to create two tables, one called "user" and one called "user_vendor." Eventually I plan on adding another extended class "guest_user" with different attributes... The way I was planning on entering vendors would be to first enter the vendor as a user and the take the id of the user table and do another insert into vendor_user using the "id" from user as a foreign key. I have a few questions. First, Would this be the best way to do this? My logic is all vendor_users would be users but not all users would be vendor_users. Second, should I create a primary key on user_vendors (another id attribute perhaps) or should I just index the forign key vendor_id? Any insights would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
digibucc Posted February 10, 2012 Share Posted February 10, 2012 why not have one table for all users and have a type column which can be "vendor, guest, standard, etc" ? then you can just check the type and take the appropriate actions there. you could even combine it into a single class. Quote Link to comment Share on other sites More sharing options...
dgruetter Posted February 10, 2012 Author Share Posted February 10, 2012 Thanks for the reply. I was actually going to include a type column, I forgot to add that. It makes sense. My question still remains on whether I should store the attributes unique to vendor in another table using the user id as a foreign key. Currently I have a foreign key in the vendor table called vendor_id (to be used for joins later in the game). But... I also have a field simply called id. This id field is the vendor tables primary id field. I was wonder if this was even needed or if I should just use the foreign key for indexing and sorting. I guess it doesn't hurt to have that extra primary key. I really need to brush up on my MYSQL skills. Quote Link to comment Share on other sites More sharing options...
digibucc Posted February 10, 2012 Share Posted February 10, 2012 one key, user id Quote Link to comment Share on other sites More sharing options...
dgruetter Posted February 10, 2012 Author Share Posted February 10, 2012 Makes sense. Thanks for the quick reply. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.