用PHP改变MYSQL字段的排序位置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用PHP改变MYSQL字段的排序位置相关的知识,希望对你有一定的参考价值。
Quick little snippet for changing the ordering of a field in a mysql database.
function changeOrderNum($currentOrderNum, $newOrderNum) { $yourTableName = ""; $orderField = ""; if($newOrderNum < $currentOrderNum) { $update1 = mysql_query("UPDATE $yourTableName SET $orderField = $orderField+1 WHERE $orderField >= '$newOrderNum' AND $orderField < '$currentOrderNum'") or die(mysql_error()); } else { $update1 = mysql_query("UPDATE $yourTableName SET $orderField = $orderField-1 WHERE $orderField <= '$newOrderNum' AND $orderField > '$currentOrderNum'") or die(mysql_error()); } }
以上是关于用PHP改变MYSQL字段的排序位置的主要内容,如果未能解决你的问题,请参考以下文章