Working with jQuery DataTables server-side processing using PHP and MySQL

Working with jQuery DataTables server-side processing using PHP and MySQL

Working with jQuery DataTables server-side processing using PHP and MySQL

In this PHP Tutorial, I am going to tell you how to use jQuery datatable plugin with Server-side processing with PHP and MySQL.

jQuery DataTables have lots of flexibility built-in by default. For example it provides sorting, pagination, searching functionality that is not so easy in HTML tables.

Using jQuery datatable, you transform your HTML table from classical to DataGridView component.

In this example, I will show you basic example of jQuery datatable to list whole data at once from MySQL database.

If there are large amount of records in your database then it can be a performance issue to get all data from server at once.

In next example, I will show you how to integrate server side pagination, searching and sorting using jQuery DataTables in PHP MySQL.

For this example, I need to obtain the library of jQuery and jQuery DataTables.

Step1: Create Employee Table

To start with this example, You should have a table with some records so I will create a new table "employee" in MySQL database by running following query :

CREATE TABLE `employee` (
 `name` varchar(255) NOT NULL,
 `age` varchar(20) NOT NULL,
 `salary` varchar(100) NOT NULL,
 `updated_at` datetime DEFAULT NULL,
Step2: Create employee.html file

In this step, I will create "employee.html" file and include the DataTables CSS in the top and in the bottom include JS files and instantiate the DataTable on the table.

<!DOCTYPE html>
   <title>Working with jQuery DataTables server-side processing using PHP and MySQL</title>
   <link rel="stylesheet" type="text/css" href="">

<div class="container">
  <h2>Working with jQuery DataTables server-side processing using PHP and MySQL</h2>
  <table id="dataTable-example">


<script type="text/javascript" src=""></script>
<script type="text/javascript" charset="utf8" src=""></script>

<script type="text/javascript">
  $(document).ready(function() {
        "bProcessing": true,
        "sAjaxSource": "employee.php",
        "aoColumns": [
              { mData: 'id' } ,
              { mData: 'name' },
              { mData: 'age' },
              { mData: 'salary' }

Step 3: Create employee.php File

In this step, I will create a "employee.php" file and configure the database and write a simple MySQL select query to get records from employee table.


define (DB_USER, "root");
define (DB_PASSWORD, "demo");
define (DB_DATABASE, "demo");
define (DB_HOST, "localhost");


$query = "SELECT * FROM employee";
$result = $conn->query($query);

while($row = $result->fetch_array(MYSQLI_ASSOC)){
  $data[] = $row;

$results = ["sEcho" => 1,
          "iTotalRecords" => count($data),
          "iTotalDisplayRecords" => count($data),
          "aaData" => $data ];

echo json_encode($results);


DataTables expect some attributes in the returned json data and they are :

  • iTotalRecords – It should be the total number of records before applying the filters.
  • iTotalDisplayRecords – It should be the total number of records after applying the filters.
  • sEcho – Must be integer type for security reason. This is an unaltered copy of sEcho sent from the client side.
  • aaData – It will return the array of data from the server.

Phone: (+91) 8800417876
Noida, 201301
ataşehir escort maltepe escort bostancı escort kadıköy escort maltepe escort ataşehir escort tuzla escort pendik escort ümraniye escort kartal escort
pendik escort
izmir escort izmir escort izmir escort izmir escort denizli escort antalya escort antalya escort antalya escort izmir escort izmir escort izmir escort izmir escort izmir escort
hatay escort nevsehir escort nigde escort kirikkale escort batman escort osmaniye escort kirklareli escort tokat escort rize escort adiyaman escort gumushane escort batman escort
porno izle
cialis satış cialis fiyat cialis 20 mg cialis 100 mg cialis 5 mg fiyat
sohbet okey oyna
ankara escort marmaris escort bursa escort mersin escort antalya escort izmir escort samsun escort bodrum escort çeşme escort kuşadası escort adana escort eskişehir escort gaziantep escort esenyurt escort pendik escort tuzla escort fatih escort ümraniye escort mecidiyeköy escort kartal escort bahçelievler escort bahçeşehir escort ataşehir escort bakırköy escort nişantaşı escort avcılar escort büyükçekmece escort kurtkoy escort konya escort beşiktaş escort taksim escort beylikdüzü escort malatya escort sakarya escort şişli escort maltepe escort kadıköy escort ataköy escort bostancı escort şirinevler escort bağcılar escort üsküdar escort etiler escort başaksehir escort ortaköy escort kağıthane escort sultangazi escort halkalı escort çekmeköy escort şaşkınbakkal escort mamak escort sincan escort keçiören escort çankaya escort beypazarı escort akyurt escort pursaklar escort kahramankazan escort göztepe escort alsancak escort bornova escort buca escort karabaglar escort karşıyaka escort konak escort narlıdere escort izmit escort başiskele escort kandira escort körfez escort karamürsel escort dilovası escort gölcük escort gebze escort kocaeli escort kayseri escort elazığ escort denizli escort diyarbakir escort adana escort ankara escort izmir escort antalya escort gaziantep escort kayseri escort konya escort mersin escort denizli escort kocaeli escort diyarbakır escort