hoponhiggo Posted April 19, 2011 Share Posted April 19, 2011 Hi Chaps I currently have 2 tables: Users - this contains basic user regisration details in the following rows: id, username, password etc Messages - this contains posts which are displayed on a page and contains the follwoing rows: messageid, message These two tables need to be linked together so that i can display the name (username) of the person who left the message. Can anybody tell me the best way to do this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/234169-linking-tables/ Share on other sites More sharing options...
requinix Posted April 19, 2011 Share Posted April 19, 2011 Add a userid field to the messages table... Quote Link to comment https://forums.phpfreaks.com/topic/234169-linking-tables/#findComment-1203591 Share on other sites More sharing options...
hoponhiggo Posted April 19, 2011 Author Share Posted April 19, 2011 Thats what i want to do, but i dont understand how to make sure the two userid are the same. If a new user registers, the userid in the users table auto increments. How would the userid make its way to the messages table? Quote Link to comment https://forums.phpfreaks.com/topic/234169-linking-tables/#findComment-1203593 Share on other sites More sharing options...
requinix Posted April 19, 2011 Share Posted April 19, 2011 When they're posting messages they aren't new anymore. They exist in the system. And if they exist they must have an ID number. When you logged them in you must have queried the database. When you do so, grab the user ID. Then when they post messages, stick that ID into your INSERT query. Quote Link to comment https://forums.phpfreaks.com/topic/234169-linking-tables/#findComment-1203606 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.