


About the implementation of drag-and-drop sorting of secondary directories (source code sample download)_PHP tutorial
Second-level directory format is often encountered in development projects. For example, article modules and product modules, many apps are based on a two-level classification format. In ordinary sorting solutions, whether it is one-level classification or multi-level classification, the administrator manually edits the value of the same-level classification sorting in the background to set the sorting, and the display order is determined based on the value. This operation method is relatively cumbersome. jQuery has a drag-and-drop method for sorting. From the user level, this operation is very intuitive and easy to operate. In a project, product classification used a two-level classification, and the display is as shown in the figure below:
Regarding the sorting issue, we decided to use jQuery’s drag-and-drop plug-in: when dragging a first-level category, the first-level category will be sorted; when dragging a sub-category under a certain level of category, the sub-category will be sorted. Drag and drop to sort.
Drag the "+" icon on the front desk of the first-level category name to sort the first-level categories.
Drag the "-" icon in front of the name of the secondary category under a certain level of classification to sort the secondary categories under this category;
The following is the database structure and program code to implement the above functions
Database structureCREATE TABLE IF NOT EXISTS `product_classify` (
`id` int(10 ) unsigned NOT NULL AUTO_INCREMENT,
`parentId` int(10) unsigned NOT NULL,
`name` varchar(50) DEFAULT NULL,
`sort` int(10) unsigned NOT NULL DEFAULT '0' ,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=27 DEFAULT CHARSET=utf8;
Import data
INSERT INTO `product_classify` (`id`, `parentId`, `name`, `sort`) VALUES
(1, 0, 'Magic props', 1),
(2, 1, 'Close-up magic', 2),
(3, 1, 'Stage magic', 1),
( 4, 1, 'Liu Qian's magic', 3),
(5, 0, 'Thousands of magic props', 2),
(6, 5, 'Mahjong Pai Gow series', 3),
( 7, 5, 'Poker series', 1),
(8, 5, 'Size series', 5),
(9, 5, 'Card changer series', 4),
(10, 5, 'High-Tech Series', 2);
Style Code
Load js file and code
<script><br>$(document).ready(function(){<br> $("#mm").sortable({<br> opacity: 0.5,<br> cursor:'move',<br> revert:true,<br> handle:'.f',<br> placeholder:'ui-move',<br> update:function(){<br> serial=$(this).sortable("serialize");<br> $("#return").load("myRun/sort.php?"+serial);<br> }<br> });<br> $("#mm div").sortable({<br> opacity: 0.5,<br> cursor:'move',<br> revert:true,<br> handle:'.t',<br> placeholder:'ui-move',<br> update:function(){<br> serial=$(this).sortable("serialize");<br> $("#return").load("myRun/sort.php?"+serial);<br> }<br> });<br> $(".f").toggle(function(){<br> if($(this).attr("src")=='images/plus.gif'){<br> $("#mm").find(".f").attr("src","images/plus.gif");//将全部大类前面的图标改为加号<br> $("#mm").find("div").hide();//隐藏子类<br> $('div',$(this).parents('.nav:first')).show();//显示当前点击大类的子类<br> $(this).attr("src","images/nofollow.gif");//将当前点击的大类前面的加号图标更改为减号图标<br> }else{<br> $(this).attr("src","images/plus.gif");<br> $('div',$(this).parents('.nav:first')).hide();//$($(this).parents('div:first')+'.odd2').hide();<br> }<br> },function(){<br> if($(this).attr("src")=='images/plus.gif'){<br> $("#mm").find(".f").attr("src","images/plus.gif");<br> $("#mm").find("div").hide();<br> $('div',$(this).parents('.nav:first')).show();<br> $(this).attr("src","images/nofollow.gif");<br> }else{<br> $(this).attr("src","images/plus.gif");<br> $('div',$(this).parents('.nav:first')).hide();//$($(this).parents('div:first')+'.odd2').hide();<br> }<br> });<br> //$('.odd2','table:first').hide();//初始化 隐藏主题分类 <--改动:在css中把子类display:none。这样可以直接显示第一个。以前的效果是全部展开,然后在全部隐藏,然后在显示第一个。不太好看。<br> $('#mm ul:first div').show();//显示第一个主题分类列表<br> $('#mm ul:first .f').attr("src","images/nofollow.gif");//改变图片为“-”状<br>});<br></script>
显示代码
//通过where条件来过滤子类,仅显示分类(一级)
$sql='select a.id,a.parentId,a.name,a.sort,count(b.id) as count from product_classify as a';
$sql.=' left join product_classify as b on b.parentId=a.id where a.parentId=0';
$sql.=' group by a.id order by a.sort';
$query=mysql_query($sql);
if(mysql_num_rows($query)){
while($arr=mysql_fetch_array($query)){
echo ' ";
}
}else{
echo '
}
?>
排序操作sort.php
include("../conn.php");
$menu=$_GET['menu'];
switch(strtolower($menu[0])){
case 'productclassify':
$table='product_classify';
break;
}
for($i=1;$i
mysql_query($sql);
}
?>
实例下载
二级目录拖拽排序的实现及演示源码下载

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The superpeople game can be downloaded through the steam client. The size of this game is about 28G. It usually takes one and a half hours to download and install. Here is a specific download and installation tutorial for you! New method to apply for global closed testing 1) Search for "SUPERPEOPLE" in the Steam store (steam client download) 2) Click "Request access to SUPERPEOPLE closed testing" at the bottom of the "SUPERPEOPLE" store page 3) After clicking the request access button, The "SUPERPEOPLECBT" game can be confirmed in the Steam library 4) Click the install button in "SUPERPEOPLECBT" and download

This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

As an indispensable accompaniment to children's growth, Beilehu's children's songs have won the love of countless parents and children with their cheerful melody, vivid pictures and entertaining and educational content. In order to allow babies to enjoy the joy brought by children's songs anytime and anywhere, many parents hope to download Beilehu's children's songs to their mobile phones or tablets so that they can listen to their children at any time, but how to save Beilehu's children's songs? On your mobile phone, this tutorial will bring you a detailed introduction. Users who don’t understand it yet can come and read along with this article to learn more. Beilehu Nursery Rhymes Download Children's Songs Multi-Picture Tutorial: Open the software and select a children's song you want to download. The editor takes "Classic Children's Songs" as an example. 2. Click the "Download" button below the children's song star.

How to download and save Douyin videos? You can download and save videos in Douyin short video APP. Most users don’t know how to download and save Douyin videos. Next is the diagram of how to download and save Douyin videos brought by the editor. Text tutorial, interested users come and take a look! Tutorial on how to use Douyin: How to download and save Douyin videos 1. First open the Douyin short video APP, enter the main page and click the [Share] button on the right; 2. After that, the multi-function bar will expand below, slide to the right to find [ Save local] icon; 3. Then you need to wait for the download, and then the [Saved, please go to the album to view] border will appear; 4. Finally jump to the album page, and you can see that the video you just downloaded has been saved.

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.
