specifically, I have a sortable with 16 spaces. in each is some text. It initially starts out with the data in the same order it is in the database. I want to make it so that after the user sorts the sortable blocks the way he wants, he can click "save" and the page rearranges the data in the database in the new order he's specified. so if previously for example the database had :
field 1 = "apples"
field 2 = "oranges"
field 3 = "pears"
field 4 = "bananas"
and so on, and the user rearranged the order to be (on the screen visually) : apples, bananas, oranges, pears, then my desired end result when "save" was pressed would be to save this in the database :
field 1 = "apples"
field 2 = "bananas"
field 3 = "oranges"
field 4 = "pears"
essentially i'm trying to make a menial data manipulation visual and intuitive. I could do this very easily in a traditional language by just doing the following in pseudo code :
- load the data in the order it appears on screen into variables;
- reassign the database fields accordingly by building the SQL necessary
- make the database call using a POST
where I'm falling down is how to do this in practice, and whether it can all be done using jquery or ajax or something else. I'm a php person but this isn't server side so my limitations are exposed lol....
what's the best way to do this? thru jquery directly, or must it be done in Ajax? (i have very little ajax knowledge) I am planning to fix this gap in my knowledge but that won't happen soon enough to solve this problem, so for the short term i need to figure out how to get this task done. help!
You would accumulate the values using jQuery (assuming they're in li's) and then send it to the server with a post call. I'm not sure what format the values would appear as on the server side but it should be an array: $_POST['order'].
this might be too much to ask, but please bear with me, I'm useless with java (but trying to learn)... any way you could explain what those lines of code are doing, and what parts of it i need to change to make it work with what I have? I'm sure it's simple stuff for java gurus but I'm not sure what I need to change in your code if anything... for reference here is the code of my test page (only the sortable and a button on it):
** note ** in reality the values in the sortables will be variables populated by database entries, but that's to be worried about later as i know how to do all that. I just want to output a post that tells my php script about the new position as the user has arranged on the screen.