var autoSave = false; in index.php controls automatic submission.
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;
}
Automatically submit the processing file 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`<{$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
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
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/