HTML
HTML 5
PHP - Dynamic Drag And Drop Table Rows Using JQuery Ajax
As we know, dynamic sorting or drag and drop list items or div or table rows, it's amazing things for client or any user to understand flow. If you create sorting with drag and drop able table rows or div for your product then it's awesome. So, in this post. i would like to share with you how to create drag and drop table rows using jquery ui and also we will make it dynamic using php. so basically we will save data into database using jquery ajax.
- TAGS
- PHP
- HTML
- Javascript
- jQuery
- 4.5/5.0
- Last updated 08 September, 2022
- By Admin
In this example we will use bootstrap for just make it better layout. we require to use jquery ui for make sortable table row. we will use cdn js or css for both so you don't require to download and save in your system for this example. Then we will create "sorting_items" table with id, title, description and position_order columns. we will manage it in one page using ajax. So just follow below few step to done this example. After complete all the steps. you will get preview like as bellow screen shot. You can also check demo and download full script of this post example.
Step 1: Create Database Table
In fist step, we need to create database and table, so here i created "laravel_test" database and "sorting_items" table with id and name column. You can simply create "sorting_items" table as following sql query.
SQL Query:
CREATE TABLE IF NOT EXISTS `sorting_items` ( `id` int(10) NOT NULL AUTO_INCREMENT, `title` varchar(120) NOT NULL, `description` text NOT NULL, `position_order` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
Step 2: Create index.php File
Here, we need to create index.php file and we will display all data and write code for sorting with drag and drop table rows. So let's create index.php file and put bellow code.
index.php
Dynamic Drag and Drop table rows in PHP Mysql- codewale.com Dynamic Drag and Drop table rows in PHP Mysql - codewale.com
query($sql); while($user = $users->fetch_assoc()){ ?> # Name Defination
Step 3: Create Database Configuration File
In this step, we require to create database configuration file, here we will set database name, username and password. So let's create "db_config.php" file on your root directory and put bellow code:
db_config.php
Step 4: Create ajaxPro.php File
In last step, we will create ajax file for save data in order. So let's create ajaxPro.php and put below code:
ajaxPro.php
$v){ $sql = "Update sorting_items SET position_order=".$i." WHERE id=".$v; $mysqli->query($sql); $i++; } ?>
Now you are ready to run example.
You can also check demo and download full script.
I hope it can help you...