Re-ordering with a gap?!?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jmansa
Forum Commoner
Posts: 81
Joined: Wed Aug 23, 2006 4:00 am

Re-ordering with a gap?!?

Post 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?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Re-ordering with a gap?!?

Post by josh »

Looks like you're reinventing the wheel. SQL has an order by "command".
jmansa
Forum Commoner
Posts: 81
Joined: Wed Aug 23, 2006 4:00 am

Re: Re-ordering with a gap?!?

Post by jmansa »

Not sure what you mean?!?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Re-ordering with a gap?!?

Post by josh »

Post Reply