reordering list help or algo needed

This is a discussion on reordering list help or algo needed within the PHP Language forums, part of the PHP Programming Forums category; tgh003@gmail.com wrote: > > So lets assume I have a list of tasks in db table (table looks ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 04-28-2005
NC
 
Posts: n/a
Default Re: reordering list help or algo needed

tgh003@gmail.com wrote:
>
> So lets assume I have a list of tasks in db table (table looks like:
> ID, task, sort)
>
> And I want to reorder the task list without updating all the records
> in the table. I dont want to run a sql update stmt against every
> record to update the "sort" field.
>
> Any other easy way to do this?


Nope; UPDATE is simple enough. You may want to keep your task list
in an InnoBD table, so that reordering could be done as a transaction.
Say, you want to move the tenth task up to the second spot:

BEGIN;
UPDATE the_table SET sort=0 WHERE ID=XXX AND sort=10;
UPDATE the_table SET sort=sort+1 WHERE ID=XXX AND task>=2 AND task<10;
UPDATE the_table SET sort=2 WHERE ID=XXX AND sort=0;
COMMIT;

(I am assuming all records in the same task list have the same ID.)

> there has got to be a simple algo out there.


What's wrong with UPDATE queries? You only need three of them
regardless of the number of items in the list...

Cheers,
NC

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:06 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0