RE: [PHP] Seeking strategy/algorithm for maintaining order of records
| From: | Arno Kuhl | Date: | Mon, 17 Oct 2011 09:08:32 +0000 |
| Subject: | RE: [PHP] Seeking strategy/algorithm for maintaining order of records | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-315330@lists.php.net to get a copy of this message | ||
From: Stephen [mailto:stephen-d@rogers.com]
Sent: 16 October 2011 11:33 PM
To: php-general@lists.php.net
Subject: Re: [PHP] Seeking strategy/algorithm for maintaining order of
records
Displaying in an order is easy when you have a field called "order".
SELECT descriptions FROM categories ORDER by order;
My issue is, say I have three records:
ID Category Order
1 B&W 1
2 Landscapes 2
3 Nudes 3
I am looking for the best way to be able to change the values to
ID Category Order
1 B&W 3
2 Landscapes 2
3 Nudes 1
Dynamically building a form, entering the new order value, and then looping
through the post, with a SQL UPDATE is the best I can come up with.
A future issue will be doing the same to the table category-photograph
ID Category_id photo_id order
This table is needed to allow a photograph to be in more than one category.
Cheers
Stephen
--
One way would be to use ajax. Each time a photo is moved up or down the
order list you issue an ajax request to update the order. That way your php
script only needs to deal with 2 records at a time and switch their order
values.
Besides that, I can't think of any way of processing a form with multiple
order changes other than looping through the post the way you described.
Cheers
Arno