PHP Simple message Board and reply function to implement _php instance

Source: Internet
Author: User
Tags php foreach

I found this tutorial on the Internet, but basically nobody said anything. Then one day I saw a PHP program designed a database design like this a lot of understanding! The following is a structure diagram of the database

Now let's go on to the introduction

ID This is the parent ID can be queried by this ID to see if there is a child ID at the same time can also record this is the ID of that message

son_id This is the child ID and then through this ID can find the corresponding parent ID
NEWS_ID record the ID of the article
Sender_author the person who took the message
Receiver_author the person who sent the message
Contents of Content Message
Status when someone replies to your post, this value turns from 0 to 1. The message is not displayed. If you don't click in, the message still exists.
Time to record a message


Message Board reply idea

When the sender (also the message of the person) to the article under the message or reply to the need for the receiver (also the author of the article or the person to be replied) to receive. Single DATABASE statement query to this key sender_author and Receiver_author will know who the receiver is and who sent the party. And then the response is displayed based on this judgment.


Prompted you to have a new message thinking

When the sender sends a message, the value of this status defaults to 0, which is the prompt to receive the send you have a new message. When clicked in, call the database modification statement to modify the specified value to 1 so it doesn't show up.

Database action statements when viewing comments

Copy Code code as follows:

Function Message ($id) {
$query = $this->db->query ("SELECT * from message WHERE news_id = ' $id '");/or post ID query for all comments inside
return $query->result ();
}

This is the code to get the parent's message content.

Copy Code code as follows:

<?php foreach ($query as $sel) {?>
<p> message User: <?php echo $sel->receiver_author;? > Message content: <?php echo $sel->content?></p>
<?php}?>

Whether the user login and give the message permission

Copy Code code as follows:

<form id= "Form1" Name= "Form1" method= "Post" action= "<?php Echo Site_url ()." /publish/user_message "?>" >
<textarea rows= "5" cols= "x" Name= "Huifu" <?php if ($uere _name = = "0") {echo "Disabled";}? > >
<?php
if ($uere _name = = "0")
{echo "Sorry you haven't logged in and can't leave a message";}
?>
</textarea>
<input class= "Wole" name= Author "value=" <?php echo $author;? > "/><!--recipient post author-->
<input class= "Wole" name= news_id "value=" <?php echo $news _idx;? > "/><!--article id-->
<input type= "Submit" name= "Submit"/>
</form>
<script language= "JavaScript" >
function Updateinfo () {
if (<?php echo $uere _name;? > = 1) {
Document.form1.Submit.value = "message";
document.form1.Submit.disabled = false;
}
else{
Document.form1.Submit.value = "Not yet logged in";
document.form1.Submit.disabled = "Disabled";
}
}
Updateinfo ();
</script>

This shows all of the child IDs and message contents after getting the specified parent ID

Copy Code code as follows:

<p> here is <?php echo $is;? > Floor User: <?php echo $sel->receiver_author;? > <br/> Message content: <?php echo $sel->content?>

<a onclick= "Showdiv (' contentid<?php echo $is;? > ', ' showtext<?php echo $is;? > ') "href=" javascript:void (0) "> Reply </a>
<div id= "contentid<?php echo $is;? > "class=" None ">
<?php
$query = $this->db->query ("SELECT * from", where son_id = ' $sel->id ' ORDER by id ');//Get the child reply of the specified parent ID
$revis = $query->result ();
foreach ($revis as $row) {?>
<p><?php if ($row->sender_author = = $row->receiver_author) {echo $row->sender_author;}
else{echo $row->sender_author. " replied: ". $row->receiver_author; >
Content is: <?php echo $row->content?></p>
<?php}?>
<form action= "<?php echo Site_url ()." /publish/son_message "?>" method= "POST" >
<input name= "Son_idx" class= "Wole" value= "<?php echo $sel->id?>"/>
<input name= "Receiver_author" class= wole "value=" <?php echo $sel->receiver_author;? > "/>
<input class= "Wole" name= news_id "value=" <?php echo $news _idx;? > "/><!--article id-->
<textarea rows= "5" cols= "a" name= "Huifux" ></textarea>
<br><input type= "Submit" Name= "sub" value= "Reply" ></form></div></p>
<script language= "JavaScript" type= "Text/javascript" >
<!--
function Showdiv (TARGETID,OBJN) {

var Target=document.getelementbyid (Targetid);
var Clicktext=document.getelementbyid (OBJN)

if (target.style.display== "block") {
Target.style.display= "None";
clicktext.innertext= "Reply";

} else {
target.style.display= "Block";
Clicktext.innertext= ' put up ';
}

}
-->
</script>


This is the effect of the implementation of the picture Message board has been implemented message content reply

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


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.