|
Posted by aaron.reese on 09/07/06 15:16
Sounds like a job for key=>value associative arrays to me.
grab the data from the database source as an array
$sort_array = array(A=>10,B=>20,C=>30,D=>40);
If you want to move C down, find the array element and add 15 to it
$sort_array[C] = $sort_array[C] + 15;
the array now looks like (A=>10,B=>20,C=>45,D=>40)
run the array through asort()
the array now looks like (A=>10,B=>20,D=>40,C=>45)
build a for loop that runs through the elements in the array and resets
them to multiples of 10
(A=>10,B=>20,D=>30,C=>40)
When the user has finished changing the sequence, save the new order
back to the database.
$SQL = "UPDATE menu SET menu.sequence = 10 WHERE menu.option = A";
If you need to add elements to the array, you can do that also, just
remember that you will also need to create the database record for it
before you try to update it.
Obiron
version2 wrote:
> Hi,
>
> i want to update each field in a database table and increment by 10.
>
> so it will look like
>
> 10, 20, 30, 40, 50
>
> if anyone can help it would be great
Navigation:
[Reply to this message]
|