/ Published in: PHP
Quick little snippet for changing the ordering of a field in a MYSQL database.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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()); } }