Php simple message board and reply function implementation. I found this tutorial on the Internet, but basically no one said anything. then one day I saw a PHP program designed a database design similar to this, and then I found a lot on the Internet. but basically no one said anything. then one day I saw a PHP program designed a database design similar to this, and I learned a lot! The following figure shows the structure of the database.
Next, let's continue with the introduction.
Id: this is the parent Id. you can use this id to query whether there is a child id under this id. you can also record the id of the message.
Son_id: this is a child id, and the corresponding parent id can be found through this id.
News_id record the document id
Sender_author: the person who receives the message
Receiver_author: the person who sent the message
Content
Status when someone replies to your post, the value is changed from 0 to 1, and the message is not displayed. if you do not click in, the message still exists.
Time records the message time
Message board reply ideas
When the sender (the person who sends the message) wants to leave a message or reply to the post, the receiver (the author of the article or the person to be replied) is required to receive the message. If the single database statement finds the keys sender_author and receiver_author, it will know who the receiver is and who the sender is. Then the response content is displayed based on this judgment.
Prompt you to have a new message idea
When the sender sends a message, the default value of this status is 0, indicating that you receive a new message. When you click in, call the database modification statement to change the specified value to 1.
Database operation statement for viewing comments
The code is as follows:
Function message ($ id ){
$ Query = $ this-> db-> query ("SELECT * FROM message WHERE news_id = '$ ID'"); // query all the comments in the article id
Return $ query-> result ();
}
This is the code for getting the parent message content
The code is as follows:
Message User: Receiver_author;?> Message content: Content?>
Whether the user logs in and gives the message permission
The code is as follows: