加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

整理一份拖拽排序自动保存的代码,后台是php

发布时间:2020-12-13 05:18:36 所属栏目:PHP教程 来源:网络整理
导读:?? ? ?? ??? ? ?? ??? ??? ? ?? ??? ??? ? ?? ??? ??? ? ?? ??? ??? ? ?? ??? ? ?? ??? ? ?? ??? ??? ? ?? ??? ??? ? ?? ??? ??? ? ?? ??? ??? ? ?? ??? ? ?? ? //拖拽 ? ? public function tuozhuaiAction() ? ? { ? ? ? ? $yidongid = Request::post('yido

?? ?

?? ??? ?

?? ??? ??? ?

?? ??? ??? ?

?? ??? ??? ?

?? ??? ??? ?

?? ??? ?

?? ??? ?

?? ??? ??? ?

?? ??? ??? ?

?? ??? ??? ?

?? ??? ??? ?

?? ??? ?

?? ?

//拖拽

? ? public function tuozhuaiAction()

? ? {

? ? ? ? $yidongid = Request::post('yidongid');//移动的ID

? ? ? ? $tuozhuaistyle = Request::post('tuozhuaistyle');//拖拽的方式

? ? ? ? $yidongorder = Request::post('yidongorder');//移动ID要参考的排序数的ID

? ? ? ? $chengenum = Request::post('chengenum');//要修改的数量

? ? ? ? $newid = Request::post('newid');//新排列

? ? ? ? $cankaoorder = $this->db->setTableName('content')->find($yidongorder);//参考的排序数

? ? ? ? $yidong = $this->db->setTableName('content')->find($yidongid);//参考的排序数

? ? ? ? if ($yidong['topstate'] == 1 && $cankaoorder['topstate'] == 1) {

? ? ? ? ? ? $data_be['topnum'] = $cankaoorder['topnum'];

? ? ? ? ? ? if ($yidong['topnum'] > $cankaoorder['topnum']) {

? ? ? ? ? ? ? ? $where = ' (topnum between ' . $cankaoorder['topnum'] . ' and ' . $yidong['topnum'] . ")and catid =" . $yidong['catid'];

? ? ? ? ? ? } else if ($yidong['topnum'] < $cankaoorder['topnum']) {

? ? ? ? ? ? ? ? $where = ' (topnum between ' . $yidong['topnum'] . ' and ' . $cankaoorder['topnum'] . ")and catid =" . $yidong['catid'];

? ? ? ? ? ? }

? ? ? ? ? ? $tuozhuai = $this->db->setTableName('content')->where($where)->getAll();//参考的排序数

? ? ? ? ? ? foreach ($tuozhuai as $v) {

? ? ? ? ? ? ? ? if ($v['id'] == $yidongid) {

? ? ? ? ? ? ? ? ? ? $this->db->setTableName('content')->update(array('topnum' => $cankaoorder['topnum']),'id=?',$yidongid);

? ? ? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? ? ? if ($tuozhuaistyle == 1) {

? ? ? ? ? ? ? ? ? ? ? ? $this->db->setTableName('content')->update(array('topnum' => $v['topnum'] + 1),$v['id']);

? ? ? ? ? ? ? ? ? ? ? ? //向下拖拽

? ? ? ? ? ? ? ? ? ? } else if ($tuozhuaistyle == 2) {

? ? ? ? ? ? ? ? ? ? ? ? //向上拖拽

? ? ? ? ? ? ? ? ? ? ? ? $this->db->setTableName('content')->update(array('topnum' => $v['topnum'] - 1),$v['id']);

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? if ($yidong['topstate'] == 0 && $cankaoorder['topstate'] == 0) {

? ? ? ? ? ? $data_be['listorder'] = $cankaoorder['listorder'];

? ? ? ? ? ? if ($yidong['listorder'] > $cankaoorder['listorder']) {

? ? ? ? ? ? ? ? $where = ' (listorder between ' . $cankaoorder['listorder'] . ' and ' . $yidong['listorder'] . ")and catid =" . $yidong['catid'];

? ? ? ? ? ? } else if ($yidong['listorder'] < $cankaoorder['listorder']) {

? ? ? ? ? ? ? ? $where = ' (listorder between ' . $yidong['listorder'] . ' and ' . $cankaoorder['listorder'] . ")and catid =" . $yidong['catid'];

? ? ? ? ? ? }

? ? ? ? ? ? $tuozhuai = $this->db->setTableName('content')->where($where)->getAll();//参考的排序数

? ? ? ? ? ? foreach ($tuozhuai as $v) {

? ? ? ? ? ? ? ? if ($v['id'] == $yidongid) {

? ? ? ? ? ? ? ? ? ? $this->db->setTableName('content')->update($data_be,$yidongid);

? ? ? ? ? ? ? ? ? ? continue;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? if ($tuozhuaistyle == 1) {

? ? ? ? ? ? ? ? ? ? $this->db->setTableName('content')->update(array('listorder' => $v['listorder'] + 1),$v['id']);

? ? ? ? ? ? ? ? ? ? //向下拖拽

? ? ? ? ? ? ? ? } else if ($tuozhuaistyle == 2) {

? ? ? ? ? ? ? ? ? ? //向上拖拽

? ? ? ? ? ? ? ? ? ? $this->db->setTableName('content')->update(array('listorder' => $v['listorder'] - 1),$v['id']);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? }

? ? }

?>

思路仅供参考

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!