php修改排序,上移下移
2024-09-25 18:35:37
/** $UpDown //移动方向,up或down $table //表名 $id //当前移动的ID $id_col //ID字段的名称 $oc_col //排序字段的名称 $where //条件 */ function MoveUpDown( $UpDown , $table , $id , $id_col = 'id' , $oc_col = 'OrderColumn' , $where = '' ) { if ( $UpDown == 'up' ){ $op = '<' ; $desc = 'desc' ;} else { $op = '>' ; $desc = '' ;} if ( $where != '' ) $where = "$where and" ; $rs =mysql_query( "select $id_col,$oc_col from $table where $where {$oc_col}{$op}=(select $oc_col from $table where $id_col=$id) order by $oc_col $desc limit 2" ); if ( $row =mysql_fetch_array( $rs )){ $id1 = $row [ $id_col ]; $oc1 = $row [ $oc_col ];} if ( $row =mysql_fetch_array( $rs )){ $id2 = $row [ $id_col ]; $oc2 = $row [ $oc_col ];} mysql_free_result( $rs ); if (isset( $id1 )){ mysql_query( "update $table set $oc_col= " . $oc2 . " where $id_col=$id1" ); } if (isset( $id2 )){ mysql_query( "update $table set $oc_col= " . $oc1 . " where $id_col=$id2" ); } echo "<script type='text/javascript'>window.location.href='" . $_SERVER ['PHP_SELF ']."' ;</script>"; exit ; //移动后刷新页面 } |
最新文章
- C#计算代码执行时间
- Android中top命令字段含义
- nim也玩一行流,nim版的list comprehension
- 解析jquery获取父窗口的元素
- ubuntu下nginx+php5的部署
- Android中的进程与线程
- PetaPoco入门(一)
- mysql 循环插入日期递增
- vIDC v2.0 强大的端口转发神器使用总结-开放内网tfs代码服务
- 手机端js事件支持(event)
- Android开发-API指南-<;uses-sdk>;
- Quartz.Net使用
- Project not selected to build for this solution configuration.
- POJ_3111_K_Best_(二分,最大化平均值)
- python之加密
- hdu 5656 CA Loves GCD(dp)
- Mysql用户相关操作
- 源码(08) -- java.util.ListIterator<;E>;
- 【zabbix系列】安装与加入host
- GPUImage实战问题解决