Home >Backend Development >PHP Tutorial >Implementation of simple message board and reply functions in PHP_PHP tutorial

Implementation of simple message board and reply functions in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:24:521595browse

I looked for tutorials about this on the Internet, but basically no one said anything. Then one day I saw a PHP program that designed a database design diagram like this, and I gained a lot of insights! The following is the structure diagram of the database

Implementation of simple message board and reply functions in PHP_PHP tutorial

Let’s continue the introduction

id This is considered 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 the child id and you can find the corresponding parent id through this id
news_id Record the id of the article
sender_author The person who accepted the message
receiver_author The person who sent the message
content The content of the message
status When someone replies to your post, the value changes from 0 to 1. When the message is no longer displayed, if you do not click in, the message still exists
time The time when the message was recorded


Message board reply ideas

When the sender (that is, the person who left a message) wants to leave a message or reply to the article, the receiver (that is, the author of the article or the person to be replied to) needs to receive it. If a single database statement queries the keys sender_author and receiver_author, you will know who the receiver is and who the sender is. Then display the reply content based on this judgment


Tips you have a new message idea

When the sender sends a message, the value of this status defaults to 0, which prompts the receiving and sending you to have a new message. When clicked in, the database modification statement is called to modify the specified value to 1 so that it will not be displayed.

Database operation statements when viewing comments


Copy code The code is as follows:
function message($id){ 
$query = $this-> db->query("SELECT * FROM message WHERE news_id = '$id'");//or query all comments in the article id
return $query->result();
}

This is the code to get the content of the parent’s message

Copy code The code is as follows:

Message user:receiver_author;?> Message content:content?>


< ?php }?>

Whether the user is logged in and given permission to leave messages

Copy code The code is as follows:
">







This shows how to get the specified parent ID and then display all the child IDs and message content in it

Copy code The code is as follows:

Here is the floor User:receiver_author;?>
Message content:content?>

Reply


$query = $ this->db->query("select * from message where son_id ='$sel->id' order by id");//Get the child reply of the specified parent id
$revis = $query- >result();
foreach($revis as $row){?>

sender_author == $row->receiver_author){ echo $row->sender_author;}
else{ echo $row->sender_author."Replied:".$row->receiver_author;}?>
The content is:content?>



" method="post">









This is the effect picture after implementation. The message board has implemented message content reply




Then this is implemented. When replying to you, it will show that you have a new message

Implementation of simple message board and reply functions in PHP_PHP tutorial

Implementation of simple message board and reply functions in PHP_PHP tutorial
http://www.bkjia.com/PHPjc/825293.html

www.bkjia.com

truehttp: //www.bkjia.com/PHPjc/825293.htmlTechArticleI looked for tutorials in this area on the Internet, but basically no one said anything. Then one day I saw a PHP programming design After publishing a database design drawing like this, there are many...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn