PHP sortable dynamic sorting is not paginated. php
Preview Map:
<?php
mysql_connect ("localhost", "root", "root");
mysql_select_db ("test");
mysql_query ("Set CHARACTER set GB2312");
if ($_post["reorder"]) {
$i = 1;
foreach ($_post["fruit"] as $fruit _id) {
$query = "Update ' fruit ' set ' order ' = ' $i ' where ' id ' = ' $fruit _id '";
mysql_query ($query);
$i + +;
}
}
?>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Song Jong Works--php sortable dynamic sort non-paged version </title>
<style>
UL li{
font-size:14px;
List-style-type:none;
Background: #33CCFF;
margin:5px;
padding:5px;
border:1px solid #666666;
width:300px;
Cursor:pointer;
}
</style>
<script language= "JavaScript" type= "Text/javascript" src= "Js/jquery-1.4.2.min.js" ></script>
<script language= "JavaScript" type= "Text/javascript" src= "Js/jquery-ui.js" ></script>
<script language= "JavaScript" type= "Text/javascript" src= "Js/ui.core.js" ></script>
<script language= "JavaScript" type= "Text/javascript" src= "Js/ui.sortable.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ (' #fruit_list '). sortable ();
});
</script>
<body>
<div align= "center" >
<form name= "Form1" method= "Post" action= "" >
<ul id= "Fruit_list" >
<?php
$query = "Select * from ' fruit ' order BY ' order ' ASC";
$result =mysql_query ($query);
while ($row =mysql_fetch_assoc ($result)) {
Echo ' <li><input type= "hidden" name= "fruit[]" value= "'. $row [" id "]. '/> '. ' ID: '. $row [' id ']. ' | ‘.‘ Name: '. $row [' name ']. ' | ‘.‘ Serial number: '. $row ["Order"]. ' </li> ';
}
?>
</ul>
<input type= "Submit" name= "reorder" value= "reorder"/>
</form>
Drag the corresponding item to sort, the smaller the number, the higher the front
</div>
</body>
PHP sortable Dynamic sorting page edition. PHP
Preview Map:
<?php
mysql_connect ("localhost", "root", "root");
mysql_select_db ("test");
mysql_query ("Set CHARACTER set GB2312");
Paging function call $common _func->pages (), $total _num as the total number of records, $page _id as the current page number, $add as the link address (optional), $pagesize as the number of news articles
function pages ($total _num, $page _id, $add, $pagesize) {
$total _page=ceil ($total _num/$pagesize);
$up = $page _id-1;
$down = $page _id+1;
if ($page _id==1) {
echo "<< home ";
}else{
echo "<a href=". $add. " page_id=1><< home </a> ";
}
if ($up <1) {
$up = 1;
echo "<span style=\" color:grey;\ ">< prev </span> ";
}else {
echo "<a href=". $add. " Page_id= ". $up." >< prev </a> ";
}
echo "<select onchange=\" window.location= ' ". $add." Page_id= ' +this.value;\ > ';
for ($i =1; $i <= $total _page; $i + +) {
if ($i = = $page _id) {
echo "<option value=\" ". $i." \ "Selected=\" selected\ "> ". $i. " /". $total _page." </option> ";
}else{
echo "<option value=\" ". $i." \ "> ". $i. " /". $total _page." </option> ";
}
}
echo "</select>";
if ($down > $total _page) {
$down = $total _page;
echo " <span style=\" color:grey;\ "> Next ></span> ";
}else {
echo " <a href=". $add. " Page_id= ". $down." > Next ></a> ";
}
if ($page _id== $total _page) {
echo "Last >>";
}else{
echo "<a href=". $add. " Page_id= $total _page> last >></a> ";
}
echo "Total". $total _num. " Each page of the record shows ". $pagesize." Article ";
}
Paging functions
$page _id=intval (Trim ($_get["page_id"));
$page _id= ($page _id== "")? " 1 ": $page _id;
$page _id= ($page _id>0)? $page _id: "1";
$pagesize =intval (Trim ($_get["pagesize"));
$pagesize = ($pagesize = = "")? " 3 ": $pagesize;
$pagesize = ($pagesize >0)? $pagesize: "3";
$begin = ($page _id-1) * $pagesize;
if ($_post["reorder"]) {
$i = $begin +1;
foreach ($_post["fruit"] as $fruit _id) {
$query = "Update ' fruit ' set ' order ' = ' $i ' where ' id ' = ' $fruit _id '";
mysql_query ($query);
$i + +;
}
}
?>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Song Jong Works--php sortable Dynamic sorting page Edition </title>
<style>
UL li{
font-size:14px;
List-style-type:none;
Background: #33CCFF;
margin:5px;
padding:5px;
border:1px solid #666666;
width:300px;
Cursor:pointer;
}
</style>
<script language= "JavaScript" type= "Text/javascript" src= "Js/jquery-1.4.2.min.js" ></script>
<script language= "JavaScript" type= "Text/javascript" src= "Js/jquery-ui.js" ></script>
<script language= "JavaScript" type= "Text/javascript" src= "Js/ui.core.js" ></script>
<script language= "JavaScript" type= "Text/javascript" src= "Js/ui.sortable.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ (' #fruit_list '). sortable ();
});
</script>
<body>
<div align= "center" >
<form name= "Form1" method= "Post" action= "" >
<ul id= "Fruit_list" >
<?php
$query = "Select * from ' fruit ' order BY ' order ' ASC";
$result =mysql_query ($query);
$total _num=mysql_num_rows ($result);
$add = "?";
$query = $query. "Limit $begin, $pagesize";
Pages ($total _num, $page _id, $add, $pagesize);
$result =mysql_query ($query);
while ($row =mysql_fetch_assoc ($result)) {
Echo ' <li><input type= "hidden" name= "fruit[]" value= "'. $row [" id "]. '/> '. ' ID: '. $row [' id ']. ' | ‘.‘ Name: '. $row [' name ']. ' | ‘.‘ Serial number: '. $row ["Order"]. ' </li> ';
}
?>
</ul>
<input type= "Submit" name= "reorder" value= "reorder"/>
</form>
Drag the corresponding item to sort it, the smaller the number the more the front <br/>
<a href= "? pagesize=<?php echo $total _num;? > > Show All </a> | <a href= "? pagesize=3" > page display </a>
</div>
</body>
Test.sql
--PhpMyAdmin SQL Dump
--Version 3.1.5-rc1
--Http://www.phpmyadmin.net
--
--Host: localhost
--Date of generation: January 08, 2011 06:22
--Server version: 5.0.18
--PHP version: 5.2.8
SET sql_mode= "No_auto_value_on_zero";
/*!40101 SET @[email protected] @CHARACTER_SET_CLIENT */;
/*!40101 SET @[email protected] @CHARACTER_SET_RESULTS */;
/*!40101 SET @[email protected] @COLLATION_CONNECTION */;
/*!40101 SET NAMES UTF8 */;
--
--Database: ' Test '
--
-- --------------------------------------------------------
--
--The structure of the table ' fruit '
--
CREATE TABLE IF not EXISTS ' fruit ' (
' id ' int (one) unsigned not NULL auto_increment,
' Name ' varchar (not NULL),
' Order ' int (4) not NULL,
PRIMARY KEY (' id ')
) Engine=innodb DEFAULT charset=gb2312 auto_increment=7;
--
--Export the data in the table ' fruit '
--
INSERT into ' fruit ' (' id ', ' name ', ' order ') VALUES
(1, ' Apple ', 5),
(2, ' Watermelon ', 2),
(3, ' pineapple ', 1),
(4, ' Peach ', 4),
(5, ' Cherry ', 3),
(6, ' oranges ', 6);
This article is inspired by others, their own time to refer to the article written by netizens, we have more comments, the original text space also by the way, in its foundation to improve a number of things, I hope you like, thank you ~
PHP sortable dynamic sequencing