January 4, 201115 yr I'm a beginner to PHP and SQL databases, so go easy on me xD So, I'm creating a small script where are user can post a message (only when logged in). The problem I have, is that I need the username to be attached to the posted message when entered in to the database. If you have any ideas about how I do this, or can recommend me some websites which can help me, please tell me :3 -Thanks in advance, Dave
January 4, 201115 yr I don't know what your database schema is but I'm guessing you would want the relationship between users and messags to be 1:m so 1 user can have many messages, a message can only have one user (author). So to do this you'd need a foreign key in your messages table to indicate which user wrote that message. So the user_id column in the message would point to the users ID, then you'd join the two up when you pull the messages out. SELECT * FROM messages INNER JOIN users ON users.id=messages.user_id;
Create an account or sign in to comment