I try to change this code to work on multiple lists too and it is also important to drag and drop the items between the lists not only in the same list: link
Here is the code what I made:
<?php require("db.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Dynamic Drag'n Drop</title>
<script type="text/javascript" src="//code.jquery.com/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/ui/1.7.3/jquery-ui.min.js"></script>
<style>
ul {margin:10px;padding:0;min-height:100px;min-width:100px;background-color:#87FFF5;}
#sortable1, #sortable2 {
float: left;
width: 400px;
}
#sortable1 li, #sortable2 li {
list-style: none;
margin: 0 0 4px 0;
padding: 10px;
background-color:#00CCCC;
border: #CCCCCC solid 1px;
color:#fff;
cursor:move;
}
#Result {
float:none;
clear:both;
width: 260px;
padding:10px;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$(function() {
$("#sortable1, #sortable2").sortable({ connectWith: ".connectedSortable", opacity: 0.6, cursor: 'move',
update: function(event,ui) {
var order = $(this).sortable("serialize") + '&action=updateRecordsListings' + '&id=' + this.id + '&item='+ui.item[0].innerHTML;
$.post("updateDB.php", order, function(theResponse){$("#Result").html(theResponse);});
}
});
});
});
</script>
</head>
<body>
<div>
<ul id="sortable1" class="connectedSortable">
<?php
$query = "SELECT * FROM records_multiple WHERE list='sortable1' ORDER BY recordListingID ASC";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<li id="recordsArray_<?php echo $row['recordID']; ?>"><?php echo $row['recordID'] . ". " . $row['recordText']; ?></li>
<?php } ?>
</ul>
<ul id="sortable2" class="connectedSortable">
<?php
$query = "SELECT * FROM records_multiple WHERE list='sortable2' ORDER BY recordListingID ASC";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<li id="recordsArray_<?php echo $row['recordID']; ?>"><?php echo $row['recordID'] . ". " . $row['recordText']; ?></li>
<?php } ?>
</ul>
</div>
<div id="Result"></div>
</body>
</html>
The drag and drop function is working now great but I have problems to save the result to the MySQL database. If I have more than one list I have to know the name of the new list where the item was dropped and the ID of the moved item. So I can save only that list and I can also change the list ID of the moved item.
If I use update: function(event,ui) the name of the list is not always correct. If I change it to receive: function(event,ui), it is correct, but calls the PHP file only if I move the item in an other list. So how could I get back in any cases the name of the list where the item was moved or droped?