Php implements the document top-down function,
The example in this article describes how to implement the article Top-Down Function in php. We will share this with you for your reference. The details are as follows:
Yesterday, the customer asked the author to stick the topic. I have never done this before. I did it with my colleagues' guidance. It was a simple task and it had been done by myself for a long time. I really lack the understanding of the program. Write a blog record.
Step 1: create two fields in the Document Table for the top-down function. One is the top field and is of the timestamp type. The default value is "Definition", which is used to store the time for the top-down operation. There is also a flag field, which is of the int type. It is used to determine whether the top is set and the top is 1, otherwise, it is 0 ..
Step 2: Modify the template page. Add the top column in the list option, and write the following code for the corresponding row:
Copy codeThe Code is as follows: <td class = "center" >{{ if $ logs [data]. flag }}< a href = "JavaScript: void (0);" onclick = "istop ('{$ logs [data]. id }}', 0) "> unpin </a >{{ else }}< a href =" javascript: void (0 ); "onclick =" istop ('{$ logs [data]. id }}', 1) "> top </a >{{/ if }}</td>
It is to use the flag to determine whether it is set to the top.
Top js corresponding to the page:
function istop(id,flag){$.ajax({type: "POST",url: "?m={{'article'|encrypt}}&a=savePost",data: "id="+id+"&flag="+flag,dataType:"json",success: function(msg){if(msg.status == "true"){ window.location= '?m={{'article'|encrypt}}';}else{ alert(msg.message);}}});}
Step 3: make some modifications to the program. Sort by top or not, then by top time, and then by default.
$sql .=" ORDER BY flag DESC,top DESC,id DESC ";
(Do you still remember the field we added ?)
This completes the article top-down function.