Hi guys,
need a pointer here, on a problem I'm trying to work through.
I have a list of variables that I want to have a priority assigned to, each line has drop down that corresponds to their priority ( ie 1 to ~).
I want to be able to move a variable to any position in the list and then adjust the items according to where that variable was placed.
now say I want to move E to position 1 as follows
Once this sort has been done it then need to update all the database once the sort is complete.
My first thought was a bubble sort, fairly simple I though.
I have a table within Sql that has the ranking positions in them, now I need to update these sets of data. so was logic was as follows:
1. pull data from database and insert into array
2. create a new array looping through the array (created in 1) until I hit my required position.
3. Add the changed reference into the array and then carry out transferring data from the first arrya, ensuring that the reference was not duplicated
4. loop through the built array and re insert into the database.
Abit long winded no?? And the list could be very long upto 1000 lines potentially ( thereby making the script a tad slow)
There must be an easier way to do this? Has anyone had any experience and give me a pointer of a better way to approach this problem.
Many thanks in advance
need a pointer here, on a problem I'm trying to work through.
I have a list of variables that I want to have a priority assigned to, each line has drop down that corresponds to their priority ( ie 1 to ~).
I want to be able to move a variable to any position in the list and then adjust the items according to where that variable was placed.
Code:
A 1
B 2
C 3
D 4
E 5 ..etc
now say I want to move E to position 1 as follows
Code:
E 1
A 2
B 3
C 4
D 5
Once this sort has been done it then need to update all the database once the sort is complete.
My first thought was a bubble sort, fairly simple I though.
I have a table within Sql that has the ranking positions in them, now I need to update these sets of data. so was logic was as follows:
1. pull data from database and insert into array
2. create a new array looping through the array (created in 1) until I hit my required position.
3. Add the changed reference into the array and then carry out transferring data from the first arrya, ensuring that the reference was not duplicated
4. loop through the built array and re insert into the database.
Abit long winded no?? And the list could be very long upto 1000 lines potentially ( thereby making the script a tad slow)
There must be an easier way to do this? Has anyone had any experience and give me a pointer of a better way to approach this problem.
Many thanks in advance