Forum Moderators: open
$(function() {
$("#sortable").sortable({
opacity: 0.8,
axis: 'y',
stop: function(i) {
$.ajax({
type: "GET",
url: "includes/updatedb_dishes.php",
data: $("#sortable").sortable("serialize")});
}
});
$("#sortable").disableSelection();
});
[pre]$("#second-sortable").sortable(
{
// PARAMETERS GO HERE
}); [/pre]
$(function() {
$("#sortable").sortable({
opacity: 0.8,
axis: 'y',
stop: function(i) {
$.ajax({
type: "GET",
<?php
if (basename($_SERVER['PHP_SELF']) == 'menus.php') {
echo 'url: "includes/updatedb_menu.php",';
}
if (basename($_SERVER['PHP_SELF']) == 'categories.php') {
echo 'url: "includes/updatedb_cats.php",';
}
if (basename($_SERVER['PHP_SELF']) == 'dishes.php') {
echo 'url: "includes/updatedb_dishes.php",';
}
?>
data: $("#sortable").sortable("serialize")});
}
});
$("#sortable").disableSelection();
});
<script type="text/javascript">
// first sortable, for sorting one list on one page and routing data to appropriate update file
// ie, <ul id="sortable">
$(function() {
$("#sortable").sortable({
opacity: 0.8,
axis: "y",
cursor: "move",
stop: function(i) {
$.ajax({
type: "GET",
<?php
if (basename($_SERVER['PHP_SELF']) == 'menus.php') {
echo 'url: "includes/updatedb_menu.php",';
}
if (basename($_SERVER['PHP_SELF']) == 'categories.php') {
echo 'url: "includes/updatedb_cats.php",';
}
if (basename($_SERVER['PHP_SELF']) == 'dishes.php') {
echo 'url: "includes/updatedb_dishes.php",';
}
?>
data: $("#sortable").sortable("serialize")});
}
});
$("#sortable").disableSelection();
});
<?php
$query = "SELECT menu_cat_name FROM menu_category";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
// clean and match output to unique <ul> id's
$category = $row['menu_cat_name'];
$category = strtolower($category);
?>
// second sortable for more than one sortable list on one page, routing to a single update script
// ie, <ul id="CATEGORY_list">
$(function() {
$("#<?php echo $category.'_list'; ?>").sortable({
opacity: 0.8,
axis: "y",
cursor: "move",
stop: function(i) {
$.ajax({
type: "GET",
url: "includes/updatedb_dishes.php",
data: $("#<?php echo $category.'_list'; ?>").sortable("serialize")});
}
});
$("#<?php echo $category.'_list'; ?>").disableSelection();
});
<?php
}
?>
</script>
[pre]
$($function(){
$("#sortable").sortable({...});
$("#sortable").disableSelection();
$("#list").sortable({...});
$("#list").disableSelection();
});[/pre]