欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

基于jQuery实现的百度导航li拖放排列效果,即时更新数据库_jquery

程序员文章站 2022-05-26 11:03:55
...
index.php中 var autoSave = false; 控制不自动提交。
index.php
复制代码 代码如下:

require 'db.php';
$query = "SELECT `id`,`order`,`name` FROM `limove` ORDER BY `order`";
$lis = mysql_query($query,$conn);
$li_count = mysql_num_rows($lis);
?>



li Move








Reset

Save


    while($li = mysql_fetch_assoc($lis)){
    echo '
  • '.$li['name'].'
  • ';
    }
    ?>





db.php
复制代码 代码如下:

static $connect = null;
static $table = '';
if(!isset($connect)) {
$connect = mysql_connect("localhost","root","");
if(!$connect) {
$connect = mysql_connect("localhost","Zjmainstay","");
}
if(!$connect) {
die('Can not connect to database.Fatal error handle by /test/db.php');
}
mysql_select_db("test",$connect);
mysql_query("SET NAMES utf8",$connect);
$conn = &$connect;
$db = &$connect;
}

自动提交处理文件 limove_process.php
复制代码 代码如下:

require 'db.php';
$fromid = $_POST['fromid'];
$fromorder = $_POST['fromorder'];
$toorder = $_POST['toorder'];
$updateorder = $toorder;
$eqf = '';
$eqt = '=';
$symbol = '-';
$notZero = 'AND `order`>1';
if($fromorder > $toorder){
$eqf = '=';
$eqt = '';
$symbol = '+';
$fromorder = $toorder;
$toorder = $_POST['fromorder'];
$updateorder = $fromorder;
$notZero = '';
}
mysql_query("START TRANSACTION",$conn);
$query = "UPDATE `limove` SET `order`=`order`{$symbol}1 WHERE (`order`>{$eqf}{$fromorder} AND `order`$return1 = mysql_query($query,$conn);
$query = "UPDATE `limove` SET `order`={$updateorder} WHERE `id`={$fromid}";
$return2 = mysql_query($query,$conn);
if($return1&$return2){
mysql_query("COMMIT",$conn);
}else {
mysql_query("ROLLBACK",$conn);
}
$query = "SELECT `id`,`order`,`name` FROM `limove` ORDER BY `order`";
$lis = mysql_query($query,$conn);
while($li = mysql_fetch_assoc($lis)){
echo '
  • '.$li['name'].'
  • ';
    }
    exit(0);

    保存按钮处理文件 limove_save.php
    复制代码 代码如下:

    require 'db.php';
    $data = explode(',',$_POST['data']);
    mysql_query("START TRANSACTION",$conn);
    $return = 1;
    foreach($data as $order => $id){
    $order++;
    $query = "UPDATE `limove` SET `order`={$order} WHERE `id`={$id}";
    $return = mysql_query($query,$conn)&$return;
    }
    if($return){
    mysql_query("COMMIT",$conn);
    }else {
    mysql_query("ROLLBACK",$conn);
    }
    $query = "SELECT `id`,`order`,`name` FROM `limove` ORDER BY `order`";
    $lis = mysql_query($query,$conn);
    while($li = mysql_fetch_assoc($lis)){
    echo '
  • '.$li['name'].'
  • ';
    }
    exit(0);

    重置按钮处理文件 limove_reset.php
    复制代码 代码如下:

    require 'db.php';
    mysql_query("UPDATE limove SET `order`=`id`");
    $query = "SELECT `id`,`order`,`name` FROM `limove` ORDER BY `order`";
    $lis = mysql_query($query,$conn);
    while($li = mysql_fetch_assoc($lis)){
    echo '
  • '.$li['name'].'
  • ';
    }
    exit(0);

    jquery-1.6.2.min.js文件下载: jquery-1.6.2.min.js
    软件包下载:limove_jb51.rar
    目录包含文件,如下图:

    基于jQuery实现的百度导航li拖放排列效果,即时更新数据库_jquery

    程序运行后界面:

    基于jQuery实现的百度导航li拖放排列效果,即时更新数据库_jquery

    作者:Zjmainstay    
    出处:http://www.cnblogs.com/Zjmainstay/