Php implements the document top-down function,

Source: Internet
Author: User

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.

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.