Ok this one should be fairly simple but Im finding it very hard. I have found a great sortable example on http://www.xmech.net/programming/jquery-ui-sortable-tutorial/ which uses the jquery ui to sort a list and save it to the database.
Mine allows you to drag and drop but is not saving to the database. here is my jquery function
<script type="text/javascript">
$(document).ready(function(){
$("#menu-pages").sortable({
update: function(event, ui) {
$.post("sortable.php", {type: "orderPages", pages: $('#menu- pages').sortable('serialize') });
}
});
});
</script>
and my php / html
<ul class="menu" id="menu-pages">
<?php
mysql_select_db($database_dbconnet, $dbconnet);
$resultq = mysql_query("SELECT * FROM `section` ORDER BY `sectorder` ASC", $dbconnet) or die(mysql_error());
while($row = mysql_fetch_array($resultq)){
printf('<li id="page_%s">%s</li>', $row['idsect'], $row['sectname']);
}
?>
</ul>
and my php file called sortable.php
require('../../../Connections/dbconnet.php');
parse_str($_POST['pages'], $pageOrder);
foreach ($pageOrder['pages'] as $key => $value) {
mysql_select_db($database_dbconnet, $dbconnet);
mysql_query("UPDATE `section` SET `sectorder` = '$key' WHERE `idsect` = '$value'", $dbconnet) or die(mysql_error());
}
as you can see I have even tried to keep the same names as the example but I cant make it go.
In looking at your jQuery, it seems you are posting JSON. I am guessing that
$_POSTis not being populated, because it only gets populated automatically for posts received in an form-encoded format. You need to read PHP raw input to get the JSON string and then you need to decode that JSON string into an object. That would be something like this:You should always at least do some basic debugging attempts before posting a question, as I imagine the fact the $_POST is empty would at least have enabled you to focus your question on the issue at hand (i.e. this has nothing to do with either sortable or the database).