JQuery UI sorting using lists

I have two lists (1 and 2), and I want to update them when an item moves from one to the other.

HTML:

<ul class="sortable" id="task-list"> <li id="listItem_1">Value 1 </li> <li id="listItem_2">Value 2 </li> <li id="listItem_3">Value 3 </li> </ul> <ul class="sortable" id="task-list-two"> <li id="listItem_4">Value 1 </li> <li id="listItem_5">Value 2 </li> <li id="listItem_6">Value 3 </li> </ul> 

JS:

 $("#task-list, #task-list-two").sortable({ handle : '.handle', connectWith: ".sortable" update : function () { var order = $('#task-list').sortable('serialize'); $("#info").load("process-sortable.php?"+order); } }); 

But I want to update the list (1 or 2). Do I need to add an additional variable to process.sortable.php ?

I am currently using foreach only for the first list (simplified):

 $task = nl2br($_POST['task']); $userid = $_SESSION['userid']; $position = $_POST['p']; $date = $_POST['date']; $i = "INSERT INTO tasks VALUES('','$task','$userid','0','$position','$date')"; $doi = mysql_query($i) or die(mysql_error()); 

Thanks in advance!

UPDATED FOREACH PHP:

 foreach ($_GET['listItem'] as $position => $item) { $list = $_GET['list']; if($list == "task-list") { $list = 1; } if($list == "task-list-two") { $list = 2; } $sql = "UPDATE `tasks` SET `position` = $position AND date = '$list' WHERE `id` = $item"; print($sql); $dosql = mysql_query($sql) or die(mysql_error()); } 
+4
source share
1 answer

You can simply pass the list identifier to a PHP page, for example:

 $("#info").load("process-sortable.php?"+order+"&list="+$(this).attr('id')); 

On the PHP page, you can create a condition for a list type.

You will also need to change the order variable to account for different lists:

 var order = $(this).sortable( "serialize" ); 
+3
source

Source: https://habr.com/ru/post/1481633/


All Articles