Posted By

Zync on 12/07/08


Tagged

mysql php change position order ordering Zync


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Zync
umang_nine


Change ordering position of MYSQL field with PHP


 / Published in: PHP
 

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

  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  

You need to login to post a comment.