• php排序算法


    功能描述:

      实现对数据点击[向上][向下]按钮,进行排序功能

    数据:

      数据id:id

      排序字段:rank_id

    if($rankNum>0){
            //echo $id;             //brand_rank
            //echo $rankNum;   //移动到的位置
            //倒序查找前$rankNum个元素
            $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;
            //倒序查找后abs($rankNum)个元素
            $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'] = "调整失败,请刷新重试!";
                $array['status'] = 2;
                echo json_encode($array);
                exit();
            }
        }
        $query = "UPDATE `#@__archives` SET `brand_rank`={$rank_id[$j]} WHERE `id`={$array_id[0]}";
        if(!$dsql->ExecuteNoneQuery($query)){
            $array['msg'] = "调整失败,请刷新重试!";
            $array['status'] = 1;
            echo json_encode($array);
            exit();
        }
        $array['msg'] = "调整成功";
        $array['status'] = 0;
        echo json_encode($array);

  • 相关阅读:
    985的方格难题
    POJ 3264 区间最大最小值Sparse_Table算法
    oracle中to_date详细用法示例(oracle日期格式转换)
    PLSQL基础知识-图片
    oracle-查询-时间条件查询
    oracle基础函数--decode
    PLSQL基础学习-文字
    python3 MD5
    CentOS7关闭防火墙方法
    CentOS 7下源码安装MySQL 5.6
  • 原文地址:https://www.cnblogs.com/xiashuo-he/p/4236189.html
Copyright © 2020-2023  润新知