我有两个列表(1 和 2),我想在一个项目从一个移动到另一个时更新它们。
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);
}
});
但我也想更新列表(1 或 2)。我需要发布一个额外的变量process.sortable.php
吗?
我目前拥有的 foreach 仅适用于第一个列表(简化):
$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());
提前致谢!
更新的 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());
}