Jump to content

Help with structure.


onthespot

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.