Datatable Pagination, Sorting and Search – Server Side (PHP/MySQl) Using Ajax

Datatable 1.10.9 has been released now, Datatable is most popular grid system in web development.Main benefit of Data-table is open source and light weighted.You can use this plugin with other css framework like bootstrap and foundation .There are a lot of datatable plugin are available which useful to improve UI experience.

I got huge response from reader on previous datatable tutorial which was DataTables Example – Server-side Processing with PHP.I have used json data in code instead of fetch data from mysql database, So i have got many request to share code with php,mysql using ajax.

Also Checkout other tutorial of Datatable,

We are using below Files,The details are:

Index.php - This file will responsible to create html and instance datatable using jquery code.
response.php - This file responsible to create database connection string and convert records into json string and returns data to Ajax method as response.
connection.php - This file responsible to create mysql database connection.

Datatable Example with PHP,MySql server side Using Ajax

Step 1: we will include jquery data-table and jquery library.

Step 2: Create HTML layout in your web page (index.php).

Step 3: Instantiate datatable object on table(index.php).

here we are passing which service/file url.

Step 4: Include connection file into top of the response.php file.

Step 5: Using parameters to create sql.

  • $params[‘order’] : This array contains order information of clicked column
  • $params[‘search’] : This array contains serach value information datatable
  • $params[‘start’] : start limit of data
  • $params[‘length’] : end limit of data

Step 6: Send json data to the index.php file.

You can download source code and Demo from below link.