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

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

WBOY
Libérer: 2016-05-16 17:51:19
original
963 Les gens l'ont consulté

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
    目录包含文件,如下图:

    程序运行后界面:

    作者:Zjmainstay    
    出处:http://www.cnblogs.com/Zjmainstay/
    Étiquettes associées:
    source:php.cn
    Déclaration de ce site Web
    Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
    Tutoriels populaires
    Plus>
    Derniers téléchargements
    Plus>
    effets Web
    Code source du site Web
    Matériel du site Web
    Modèle frontal