将可移动菜单链接写入数据库

时间:2011-03-26 14:09:32

标签: php mysql

我创建了一个菜单,我可以互相移动链接。现在链接的位置在我的数据库中,我想更新这些,我已经写了下面的javascript代码,以及php代码来做到这一点。但是在链接移动后如何调用updateDB.php?并将这些新职位写入我的数据库。

updateDB.php

<?php
require ("index.php");

$action = $_POST['action'];
$updateRecordsArray = $_POST['recordsArray'];

if ($action == "menu") {
    $listingCounter = 1;
    foreach ($updateRecordsArray as $recordIDValue) {
        $query = "UPDATE records SET position = ".$listingCounter." WHERE position =".$recordIDValue;
        mysql_query($query) or die('Error, insert query failed');
        $listingCounter = $listingCounter + 1;
    }
    alert("in updateDB.php");
    echo '<pre>';
    print_r($updateRecordsArray);
    echo '</pre>';
    echo 'If you refresh the page, you will see that records will stay just as you modified.';
}
?>

admin.js

 $(document).ready(function(){
    // admin scripts here    
    // Drag and drop.
    $(function(){
        $("#menu").sortable({
            opacity: 0.6,
            cursor: 'move',
            update: function(){
                var order = $(this).sortable("serialize") + '&action=menu';
                $.post("includes/updateDB.php", order, function(theResponse){
                    $("#menu ul").html(theResponse);
                });
            }
        });
    });
});

0 个答案:

没有答案