[connected sortables] Pulling hair at this idea. I need to send a variable with my receive callback to change a DB value.

[connected sortables] Pulling hair at this idea. I need to send a variable with my receive callback to change a DB value.

Page setup:

  1. Mylist1       Mylist2         Mylist3
  2. content      content      content
  3. content      content      content
Each of these lists are generated with a separate php file with its own SELECT query (if the DB's content has a boxid of 3, then its printed to list 3. WHERE boxid = 3 for example)

Each of these sortables has the class biglist and I've used connectWith and containment to allow content to be sorted between them (only visually, doesn't save on page reload)

How I am generating the content (Example of the 8th List):

  1. function eighthboxlist() 
  2. {
  3. $('#myList8').sortable({ // Renders items as "sortable"
  4. connectWith: $('.biglist'),
  5. placeholder: 'help',  // css class for the final position of the element if I wanted to re-add .help to the style page
  6. revert: true,  // seems to work well
  7. axis: 'vertically',
  8. opacity: 0.4,
  9. containment: 'parent',
  10. update : function (sorted) 
  11. // Callback Function, modifies the list
  12. serial = $('#myList8').sortable('serialize'); // Time to serialize that mofo
  13. $.ajax({
  14. url: "sort.php",
  15. type: "POST",
  16. data: serial,
  17. success: function(feedback)
  18. $('#data').html(feedback); 
  19. });      
  20. }
  21. });
  22. $('#myList8').sortable("refresh"); 
  23. }
  24. }
  25. });
  26. }
Two of the functions there just handle edit-in-place functionality but you can see I call 'eighthboxlist.php'

Which looks like so:


  1. <?php

  2. // Connect to the DB
  3. include("config.php");

  4. $resultsixth = mysql_query('SELECT itemid,content,rating,boxid FROM `Items` WHERE boxid = 8 ORDER BY `Order`'); 

  5. while($row = mysql_fetch_array($resultsixth))

  6. {


  7. $contenteight .= '<div id="drag_' . $row{'itemid'} . '" class="fudge list_element" box='.$row{'boxid'}.'>

  8. <span id="' . $row{'itemid'} . '"><span class="names" id="' . $row{'itemid'} . '">'.$row{'content'}.'</span> (<span id="' . $row{'itemid'} . '" class="lol">' . $row{'rating'} . '</span>)</span>

  9. </div>'."\n";
  10. }

  11. // return list of elements

  12. echo $contenteight;

  13. ?>

So here's the big question and problem. When an item is moved from list 1 to say list 8 I want the receive function to identify that the items boxid *WAS* 1, but now its moved to list 8 so the boxid should update to 8. That way when the user visits the page the next time - the proper position is saved.

(Incase anyones wondering about the ajax update : function (sorted) and sort.php that just orders and saves the divs position WITHIN its own list.)