jQuery连接的可排序列表,将订单保存到MySQL [英] jQuery Connected Sortable Lists, Save Order to MySQL
问题描述
希望使用此演示程序,可以在两列之间或之间拖动项目,并实时或使用保存"按钮将其更新到MySQL.重要的是您可以进行更改,然后稍后返回页面以查看或更新您的订购.
Hoping that using something like this demo it is possible to drag items within and between two columns, and update their order either live or with a "save" button to MySQL. Point being that you can make changes and return to the page later to view or update your ordering.
http://pilotmade.com/examples/draggable/
仅对一列进行操作就可以了,但是当我尝试传递两列的顺序时,问题似乎是将带有jQuery的多个序列化数组传递给PHP/MySQL更新脚本.
Doing it for just one column is fine, but when I try to pass the order of both columns, the issue seems to be passing multiple serialized arrays with jQuery to a PHP/MySQL update script.
任何见识将不胜感激.
如果您在下面看,我想通过说...
If you look below, I want to pass say...
sortable1
0
entry_5 => 1
sortable1
entry_1 => 0
entry_5 => 1
sortable2
entry_3 => 0
entry_2 => 1
entry_4 => 2
sortable2
entry_3 => 0
entry_2 => 1
entry_4 => 2
这最终完成了窍门
HTML
<ol id="sortable1"><li id="entry_####">blah</li></ol>
jQuery
<script type="text/javascript">
$(function()
{
$("#sortable1, #sortable2").sortable(
{
connectWith: '.connectedSortable',
update : function ()
{
$.ajax(
{
type: "POST",
url: "phpscript",
data:
{
sort1:$("#sortable1").sortable('serialize'),
sort2:$("#sortable2").sortable('serialize')
},
success: function(html)
{
$('.success').fadeIn(500);
$('.success').fadeOut(500);
}
});
}
}).disableSelection();
});
这是PHP查询
parse_str($_REQUEST['sort1'], $sort1);
foreach($sort1['entry'] as $key=>$value)
{
do stuff
}
推荐答案
我要做的就是将它们拆分
what I would do is split them up
data :
{
sort1:$('#sortable1').sortable('serialize'),
sort2:$('#sortable2').sortable('serialize')
}
然后,当您发布信息时,您可以获取请求并根据需要进行设置,希望如此
then when you post you can get the request and set them as needed, I hope that makes sense
所以我要做的是
parse_str($_REQUEST['sort1'],$sort1);
foreach($sort1 as $key=>$value){
//do sutff;
}
这篇关于jQuery连接的可排序列表,将订单保存到MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!