Change ordering position of MYSQL field with PHP


/ Published in: PHP
Save to your folder(s)

Quick little snippet for changing the ordering of a field in a MYSQL database.


Copy this code and paste it in your HTML
  1. function changeOrderNum($currentOrderNum, $newOrderNum) {
  2. $yourTableName = "";
  3. $orderField = "";
  4.  
  5. if($newOrderNum < $currentOrderNum) {
  6. $update1 = mysql_query("UPDATE $yourTableName SET $orderField = $orderField+1 WHERE $orderField >= '$newOrderNum' AND $orderField < '$currentOrderNum'") or die(mysql_error());
  7. } else {
  8. $update1 = mysql_query("UPDATE $yourTableName SET $orderField = $orderField-1 WHERE $orderField <= '$newOrderNum' AND $orderField > '$currentOrderNum'") or die(mysql_error());
  9. }
  10. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.