Jump to content

Recommended Posts

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. 

Link to comment
https://forums.phpfreaks.com/topic/224931-a-little-help-linking/
Share on other sites

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)

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.