PHP Sorting algorithm

Source: Internet
Author: User

Function Description:

Implement the sort function by clicking the [up] [down] button on the data

Data:

Data Id:id

Sort field: rank_id

if($rankNum>0){        //echo $id;   Brand_rank//echo $rankNum; Move to position//reverse lookup before $ranknum elements        $rankNum++; $query= "SELECT ID, brand_rank from ' #@__archives ' WHERE ' Brand_rank ' <={$id} and ' typeID ' =28 and ' Arcrank ' >-1 ORDER by ' Brand_rank ' DESC limit {$rankNum}"; }Else if($rankNum< 0){        //echo $id;        Echo $rankNum; Reverse lookup after ABS ($rankNum) elements        $rankNum=ABS($rankNum); $rankNum++; $query= "SELECT ID, brand_rank from ' #@__archives ' WHERE ' Brand_rank ' >={$id} and ' typeID ' =28 and ' Arcrank ' >-1 ORDER by ' Brand_rank ' ASC limit {$rankNum};"; }    $dsql->setquery ($query); $dsql-Execute ();  while($row=$dsql-GetArray ()) {        $array _id[]=$row["id"]; $rank _id[] =$row["Brand_rank"]; }    $count _num=Count($array _id); $array[' data '] =Array(); $j= 0;  for($i= 1;$i<$count _num;$i++,$j++){        $query= "UPDATE ' #@__archives ' SET ' Brand_rank ' ={$rank _id[$j]} WHERE ' id ' ={$array _id[$i]}"; if(!$dsql->executenonequery ($query)){            $array[' msg '] = "adjustment failed, please refresh retry!" "; $array[' status '] = 2; EchoJson_encode ($array); Exit(); }    }    $query= "UPDATE ' #@__archives ' SET ' Brand_rank ' ={$rank _id[$j]} WHERE ' id ' ={$array _id[0]} "; if(!$dsql->executenonequery ($query)){        $array[' msg '] = "adjustment failed, please refresh retry!" "; $array[' status '] = 1; EchoJson_encode ($array); Exit(); }    $array[' msg '] = ' adjustment successful '; $array[' status '] = 0; EchoJson_encode ($array);

PHP Sorting algorithm

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.