onthespot Posted July 6, 2009 Share Posted July 6, 2009 I have a user table in my database. And am looking for a way to add comments onto those users, but surely the comments would be better stored away from the user table, in a comments table. What would be the best way to go about one user posting a comment on another users profile. In theory, it will say comment from user1, comment to user2, and the comment itself. Any guidance would be of great help. Link to comment https://forums.phpfreaks.com/topic/164926-help-with-structure/ Share on other sites More sharing options...
seventheyejosh Posted July 6, 2009 Share Posted July 6, 2009 well, assuming you're auto incrementing some kind of `id` field on the users table, just do: to_id | from_id | comment with to and from corresponding to the id of the user sending / recieving the comment Link to comment https://forums.phpfreaks.com/topic/164926-help-with-structure/#findComment-869684 Share on other sites More sharing options...
onthespot Posted July 6, 2009 Author Share Posted July 6, 2009 I dont use IDs, i use usernames, could i just put from one username to another. But what when then are crossing tables? Link to comment https://forums.phpfreaks.com/topic/164926-help-with-structure/#findComment-869693 Share on other sites More sharing options...
seventheyejosh Posted July 6, 2009 Share Posted July 6, 2009 im not sure what exactly you mean by crossing tables, but if each username is going to be unique u can just do table: to_user | from_user | comment then, assuming you are haveing users login, and selecting who to send to from, say a drop down, the code will just be like this: $me=$_SESSION['username']; $to=$_REQUEST['to']; $comment=$_REQUEST['comment']; $query="INSERT INTO `comments` (`from_user`,`to_user`,`comment`) VALUES ('$me','$to','$comment')"); Link to comment https://forums.phpfreaks.com/topic/164926-help-with-structure/#findComment-869699 Share on other sites More sharing options...
haku Posted July 6, 2009 Share Posted July 6, 2009 As a side note, you should probably start using IDs for your users. If you don't, you cannot change their username, or you will lose everything they have ever done until that point, since all references are to their username. If they have an ID, you can use the ID as their reference instead, and then you can make the username whatever you want, and change it whenever you want. Link to comment https://forums.phpfreaks.com/topic/164926-help-with-structure/#findComment-869700 Share on other sites More sharing options...
onthespot Posted July 6, 2009 Author Share Posted July 6, 2009 Thanks for the replies, thats the exact thing i was looking for. And yes i understand about using IDs, i shal add them in cheers Link to comment https://forums.phpfreaks.com/topic/164926-help-with-structure/#findComment-869707 Share on other sites More sharing options...
onthespot Posted July 6, 2009 Author Share Posted July 6, 2009 Ok I want there to be a comments box on peoples profiles. And then another user can come along and leave a comment. The comment will show on the profile. So do I just have the comment table, with user to and from and the comment, and possibly now() for the time the comment was made. That would work yeah? Link to comment https://forums.phpfreaks.com/topic/164926-help-with-structure/#findComment-869742 Share on other sites More sharing options...
haku Posted July 9, 2009 Share Posted July 9, 2009 yep. Link to comment https://forums.phpfreaks.com/topic/164926-help-with-structure/#findComment-871781 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.