PHP Interface Implementation Drag-and-drop sequencing steps

Source: Internet
Author: User
This time for everyone to bring PHP interface to implement the drag-and-drop sequencing steps, PHP interface to achieve the attention of the drag-and-drop sorting, the following is the actual case, take a look.

How can we achieve the highest efficiency?

First analyze a scene, if there is a page has 10 data, so-called drag is in the 10 data to the back and forth of the drag, but each drag will affect the other data such as drag the last one to the front, then nine automatically backward, and vice versa, hmm ~ ~ ~

First imagine that the row ordinal is fixed, as if there are 10 chairs, each seat is fixed there, moving is the person above, so that it will not affect the data of other pages and everyone is also the other person's table and chairs number, so also do not have to think how much to add to the row where.

Interface design:

$ids the ID collection of the 10 data, comma-separated string//$oldIndex original position, counting from 0//$newIndex position to drag function dragsort ($ids, $oldIndex, $newIndex) {  //Guaranteed to find the data in the same order as the front table commits, here to order by field  //id primary key sort value  $sql = "Select Id,sort from table name where ID in ($ids) o Rder by field (ID, ". $ids. ") ";  $list = "Omitted here, is to go to the database to find";  ID Collection  $IDARR  = [];  Sort set  $SORTARR = [];  foreach ($list as $item) {    $IDARR []  = $item [' id '];    $SORTARR [] = $item [' sort '];  }  Record the ID you want to drag  $oldValue = $idArr [$oldIndex];  Delete the ID unset to be dragged  ($IDARR [$oldIndex]);  Insert a new position and automatically shift the  Array_splice ($IDARR, $newIndex, 0, $oldValue);  Reset sort  $set = [];  for ($i = 0; $i < count ($IDARR), $i + +) {     $set [$i] [' id ']  = $IDARR [$i];     $set [$i] [' sort '] = $SORTARR [$i];   }  Save to Database omitted}

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

PHP7 Operation MongoDB Additions and deletions to investigate the steps

A detailed description of the PHP operation Redis Step

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.