Home >Web Front-end >JS Tutorial >Baidu navigation li drag-and-drop arrangement effect based on jQuery, updating the database in real time_jquery

Baidu navigation li drag-and-drop arrangement effect based on jQuery, updating the database in real time_jquery

WBOY
WBOYOriginal
2016-05-16 17:51:19956browse

var autoSave = false; in index.php controls automatic submission.
index.php

Copy code The code is as follows:

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
Copy code The code is as follows:

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;
}

Automatically submit the processing file limove_process.php
Copy code The code is as follows:

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`<{$eqt}{$toorder} {$notZero})";
$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);

    Save button processing file limove_save.php
    Copy code The code is as follows:

    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);

    Reset button processing file limove_reset.php
    Copy code The code is as follows:

    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'].'< /li>';
    }
    exit(0);

  • jquery-1.6.2.min.js file download: jquery-1.6.2.min.js
    Software package download: limove_jb51.rar The
    directory contains files, as shown below:

    Interface after running the program:

    Author: Zjmainstay  
    Source: http://www.cnblogs.com/Zjmainstay/
    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn