PHP develops simple guestbook administrator operation function

6.png

Continue to use the LyDB class of the database set in the previous chapter.

Each user's message will generate an id in the database.

We only need to delete this message by deleting the id value in the database

Create a public calling function to delete the id in the database

<?php
  $sql="selete * from ly where id=$id";
 mysqli_query($this->link,$sql);
?>

The administrator reply function is relatively complicated

The id of the reply message is uncertain, and is generally passed through the database query statement Cyclically display messages on the page

Only clicks can be determined. Here you need to give a click time. Here we use class to implement the click event

<a href="<?php echo $row["id"];?>" class="reply_button">回复</a>

There is another knowledge point to mention here

<input type="hidden" /> Define hidden fields. Hidden fields are not visible to the user. Hidden fields usually store a default value, and their values ​​can also be modified by JavaScript.

Generally we will hide the form and display it when an event occurs.

Here we will first let the administrator reply <input> hide it. When the click-to-reply event occurs, A reply box pops up to proceed to the next step

<script type="text/javascript">
$(".reply_button").click(function(){
 if($(this).parent().parent().children(".m").children(".reply_form_wrap").size()==0){
  var id=$(this).attr("href");  
  var reply_form=$("#reply_form").html();
  $(this).parent().parent().children(".m").append(reply_form);  
  $(this).parent().parent().children(".m").children(".reply_form_wrap").show(200);
  $(this).parent().parent().children(".m").children(".reply_form_wrap").children("form").children("input[name='id']").val(id);
 }
 return false;
});
</script>

Note:

parent() obtains the parent element of each element in the current set of matching elements. Filtering with a selector is optional.

children() is to obtain subclasses.

attr() method sets or returns the attribute value of the selected element.

append() method inserts specified content at the end of the selected element.



Continuing Learning
||
<a href="<?php echo $row["id"];?>" class="reply_button">回复</a>
submitReset Code