首页 > 代码库 > php排序算法
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);
php排序算法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。