Re-ordering with a gap?!?

Discussion in 'PHP' started by jmansa, Jan 31, 2009.

  1. #1
    I have this re-ordering script which works just fine if the numbers it reorders from is in sequal like this (1,2,3,4,5,6,7,8,9)...

    But if a record is deleted, lets say record "5" I have a problem reordering from 4 to 6... Here is my script...

     
    if ($direction == "down") {
                    
                    $result = $db->sql_query("UPDATE ".$prefix."_links SET order_no = (order_no - 1) WHERE uid = $uid AND catid = '$catid' AND order_no = ($order + 1)");
                    
                    $result = $db->sql_query("UPDATE ".$prefix."_links SET order_no = (order_no + 1) WHERE uid = $uid AND linkid = '$linkid'");
    PHP:
    As it is now it only raise or lower the "order_no" by one and then no changes are made if there is a gap in my order_no... How do I solve this?
     
    jmansa, Jan 31, 2009 IP