Topic: PHP/MySQL: reordering table entries (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=28693" title="Pages that link to Topic: PHP/MySQL: reordering table entries (Page 1 of 1)" rel="nofollow" >Topic: PHP/MySQL: reordering table entries <span class="small">(Page 1 of 1)</span>\

 
GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

IP logged posted posted 12-03-2006 13:56 Edit Quote

hello,

i have a table that contains some entries in a specific order. now i want the user to be able to reorder them by clicking a "move up" or "move down" button.

how could i do the sql layout of this table and how could i perform the reording? can it be done using one variable only?

thanks!

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 12-03-2006 16:31 Edit Quote

ok... the 'most common' way to define arbitary ordering in sql tables is to use a double ( floating point number).
Then it's reasonably easy to move a row between to others just by doing rowInBetween = (rowAbove.order + rowBelow.order) / 2.

Some care to renumber everything when you run out of precision, and you're ready to go.


So long,

->Tyberius Prime

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

IP logged posted posted 12-03-2006 16:43 Edit Quote

that's a good idea! thanks!

when using double i shouldnt run out of precision in a long while, right?

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 12-03-2006 18:06 Edit Quote

depends on how much reordering your users do .

But a double should last you a loooong time.
And you can always add a cron that simply retrieves them in order, and stores them again with a new (integer) order key.

Lurch
Paranoid (IV) Inmate

From: Behind the Wheel
Insane since: Jan 2002

IP logged posted posted 12-08-2006 11:11 Edit Quote

yeah, that's typically how i have done it in the past.

either that, or for a quick add-on to an existing list, where the re-ordering will be done only by an admin (most often- ME) i would have just put an extra field in the table, where i manually enter an order int. that's not very nice, and not very quick and simple like the "move up /down" method

but I am going to work the scriptaculous draggable lists into my next "re-ordering" project. here is a link to a PHP wrapper for the scriptaculous lists... should make re-ordering lists a lot quicker, easier, (more fun??! haha) for the user. also, its pretty cool

http://www.gregphoto.net/sortable/index.php

haven't been at the asylum in a long time, but glad to be back, will take a look at whats been going on!

-lurch



Post Reply
 
Your User Name:
Your Password:
Login Options: Remember Me On This Computer
 
Your Text:
Loading...
Options: Show Signature
Enable Slimies
Enable Linkwords

« BackwardsOnwards »

Show Forum Drop Down Menu