takn25 Posted January 19, 2011 Share Posted January 19, 2011 Hi, I am facing a slight problem I have created a comment box, where users can post while logged in. The thing I can not figured out is how to link, user details from the user table with the comments table. The furthest I have gotten is posting, all user details in the comments table but this is not useful as once the user details are posted, in the comments table they wont update, if the user changes his first name for instance. So please could some one guide me a bit what can I do so this all works. Thanks in advance I hope I was clear enough on what I am after. Quote Link to comment https://forums.phpfreaks.com/topic/224931-a-little-help-linking/ Share on other sites More sharing options...
jdavidbakr Posted January 19, 2011 Share Posted January 19, 2011 Have one table that is your user table, which should have a primary key (auto-increment most likely). In the comments table, don't put the user's name, instead put the ID from the user table. Then, when you list the comments, you can perform a join to get the information from the user table, including the current name (and avitar and whatever else you might need). So your tables might be: user ------ user_id (primary autoincrement) user_name comment ------ comment_id (primary autoincrement) user_id (foreign key referencing the user table) comment_text to get the username and comment list: select user_name, comment_text from comment join user using (user_id) Quote Link to comment https://forums.phpfreaks.com/topic/224931-a-little-help-linking/#findComment-1162054 Share on other sites More sharing options...
takn25 Posted January 20, 2011 Author Share Posted January 20, 2011 Thanks for the help with your guidance I figured it out! Quote Link to comment https://forums.phpfreaks.com/topic/224931-a-little-help-linking/#findComment-1162272 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.