Page 1 of 1

Re-ordering with a gap?!?

Posted: Sat Jan 31, 2009 8:18 am
by jmansa
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...

Code: Select all

 
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'");
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?

Re: Re-ordering with a gap?!?

Posted: Sat Jan 31, 2009 8:45 am
by josh
Looks like you're reinventing the wheel. SQL has an order by "command".

Re: Re-ordering with a gap?!?

Posted: Sat Jan 31, 2009 11:17 am
by jmansa
Not sure what you mean?!?

Re: Re-ordering with a gap?!?

Posted: Sat Jan 31, 2009 11:29 am
by josh