From: Stephen [mailto:stephe...@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


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to