i have this problem already searched for the answer but still no results so i came here for help.
So i started using today this plugin from jquery "Sortable"
http://api.jqueryui.com/sortable/
And its pretty nice but the position from this plugin always start at 0 to ... and i would like to put this 1 to ..., so instead of starting at 0 i would like to start at 1.
Any help will be appreciated,
The code to insert into database:
<?php
mysql_connect('localhost','root','valesilveira4850');
mysql_select_db('valesilveira') or die( "Unable to select database");
parse_str($_POST['pages'], $pageOrder);
foreach ($pageOrder['page'] as $key => $value) {
mysql_query("UPDATE dados SET `posicao` = '$key' WHERE `id` = '$value'") or die(mysql_error());
}
?>
And the script from sortable:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.3/jquery-ui.min.js"></script>
<script language="javascript">
$(document).ready(function(){
$("#menu-pages").sortable({
update: function(event, ui) {
$.post("ajax.php", { type: "orderPages", pages: $('#menu-pages').sortable('serialize') } );
}
});
});
</script>
Cumps.
Javascript array has zero based indexing. If you need to show or input indexes, make +/- 1 adjustments.