I know this question has been asked before but the solutions did not work for me. I am trying to save the new ordering of items to the database.
I have simplified it very considerably but this is the basic idea of it. I have a form with a sortable list embedded in it.
<form id="itemlist">
<ul id="itemsort">
<li id="Item_1">Item<input type="hidden" name="itemid[]" value="itemsRowID01"/></li>
<li id="Item_2">Item<input type="hidden" name="itemid[]" value="itemsRowID02"/></li>
<li id="Item_3">Item<input type="hidden" name="itemid[]" value="itemsRowID03"/></li>
<li id="Item_4">Item<input type="hidden" name="itemid[]" value="itemsRowID04"/></li>
</ul>
</form>
I have JQuery and JQuery UI Loaded and the The Following code enables the sortable list function and posts the item ids and New sort order to a php script. the "editor" variable is a public variable that is set on load it works fine. The sorting works fine but the neworder value that posts doesn't seem to change when I re-order the list.
//sorting feature
$("#itemsort").live('hover', function() {
$("#itemsort").sortable({
opacity:.5,
update : function () {
var neworder = $('#itemsort').sortable('serialize');
var inputs = serializePost('#itemlist');
$.post("core/actions.php",{
'order': editor,
'inputs': inputs,
'neworder': neworder},function(){
alert("Order saved.", 1);
});
}
});
});
On actions.php...
if(isset($_POST['order'])){
//set a variable for each post
$batchid = $_POST['inputs']['itemid'];
parse_str($_POST['neworder'], $neworder);
//count the number of entries to be ordered
$count = count($batchid);
//use the count to create an incremental loop for each item to be updated.
$i=0;
while ($i <= $count) {
$query ="UPDATE {$_POST['order']} SET order=$neworder[item][$i] WHERE id=$batchid[$i]";
++$i;
}
}
I'm not sure why the order I get for each item will not change.
Any Ideas?
-L
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…