PHP Simple message Board and reply function specific implementation _php Tutorial

Source: Internet
Author: User
Tags php foreach
I found this tutorial on the Internet, but basically, no one said anything. And then one day I saw a PHP program design a database design like this, there is a lot of understanding! The following is a diagram of the database structure

Let's move on to the introduction

ID This is the parent ID can be queried by this ID to see if there is a child ID under this ID can also record this is the message ID

son_id This is a child ID and then this ID can be used to find the corresponding parent ID.
NEWS_ID record the ID of the article
Sender_author the person who received the message
Receiver_author the person who sent the message
Contents of Content Message
Status when someone replies to your post this value from 0 to 1 when the message is not displayed if not clicked the message still exists
Time to record a message


Message Board reply idea

When the sender (also on the message to the person) to the article to leave a message or reply to the time of the need to receive (also the author of the article or the person to be replied to) to receive. Single DATABASE statement query to this key sender_author and Receiver_author will know who the receiver is and who the sender is. And then, on the basis of that judgment, show the reply.


Tip You have a new message idea

When the sender sends a message, the value of this status defaults to 0 and prompts you to receive a new message. Call the database modification statement to change the specified value to 1 when clicked in. So it doesn't show up.

Database operation statements when viewing comments

Copy the Code code as follows:
Function Message ($id) {
$query = $this->db->query ("SELECT * from message WHERE news_id = ' $id '");//or Post ID query all comments inside
return $query->result ();
}

This is the code that gets the content of the parent's message.

Copy the Code code as follows:

Message User: receiver_author;? > Message content: content?>



Whether the user login and give the message permission

Copy the Code code as follows:


This is the display of getting the specified parent ID to display all of his child ID and message content

Copy the Code code as follows:

This is the building User: receiver_author;? >
Message content: content?>

', ' Showtext ') "href=" javascript:void (0) "> reply
"class=" None ">
$query = $this->db->query ("SELECT * from a message where son_id = ' $sel->id ' ORDER by id");//Gets 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;}? >
Content is: content?>






This is the implementation of the message board has realized the message content reply

And then this is the realization of the reply you will show you have a new message


http://www.bkjia.com/PHPjc/825293.html www.bkjia.com true http://www.bkjia.com/PHPjc/825293.html techarticle I found this tutorial on the Internet, but basically, no one said anything. And then one day I saw a PHP program design a database design like this, there are a lot of ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.