Server-side Processing DataTables using PHP with MySQL

Server-side Processing DataTables using PHP with MySQL

In this Post We Will Explain About is Server-side Processing DataTables using PHP with MySQL With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to DataTables Example – Server-side Processing with PHP Example

In this post we will show you Best way to implement jQuery Datatables Server Side Processing with PHP & MySQL, hear for DataTables – Server-side Processing in Codeigniter using Ajax with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

DataTables Server-side Processing using PHP with MySQL

DataTables is a one type of the jQuery External library used to Show the list of all Database records in a HTML View table with an dynamic interface.and then DataTables includes some more features like as a dataTable search, dataTable pagination, dataTable sort, dataTable filter and more dataTable features available.”DataTables Server-side”

Include External Libs

	<link rel="stylesheet"  href="datatables.min.css">	
	<link rel="stylesheet"  href="style.css">	
	<script src="jquery-1.11.2.min.js" type="text/javascript"></script>
    <script src="datatables.min.js" type="text/javascript"></script> 	

index.php

The following source code shows the HTML DataTable source code for the dynamic DataTable.

<body>
<div class="container">
	<table id="student-details" class="live-dt nowrap" cellspacing="0" width="100%">
	<thead>
		<tr>
		<th>Student First Name</th>
		<th>Student Last Name</th>
		<th>Student Address</th>
		<th>Student Phone</th>
		<th>Student DOB</th>
		</tr>
	</thead>
	</table>
	</div>
</body>

index.js

The following source code Display the jQuery based DataTable all the row initialization by setting custom the required some DataTable each property.and then It’s server Side PHP based property is set as Boolean value set like as a true and the server side PHP file path is some set specified for call the Ajax property.

// call do_server.php using jquery
$(document).ready(function() {
    $('#student-details').dataTable({
		"scrollX": true,
		"pagingType": "numbers",
        "processing": true,
        "serverSide": true,
        "ajax": "do_server.php"
    } );
} );

do_server.php

do_server.php files declares the database config setting configuration details store, student table name, all the columns and sends then to the simple external domain class to process the MySQL SELECT query.

<?php

//devloped by Pakainfo.com DB table to use
$db_table = 'tbl_contact';
 
//devloped by Pakainfo.com Table's primary key
$primaryKey = 'id';

$stud_data_col = array(
    array( 'db' => 'fname', 'dt' => 0 ),
    array( 'db' => 'lname',  'dt' => 1 ),
    array( 'db' => 'stud_address',   'dt' => 2 ),
    array( 'db' => 'stud_phone', 'dt' => 3,),
    array( 'db' => 'stud_date_of_birth','dt' => 4,
        'formatter' => function( $d, $row ) {
            return date( 'd-m-Y', strtotime($d));
        }
    )
   
);
 
//Live SQL server database connection information
$stud_details = array(
    'user' => 'live24u',
    'pass' => '[email protected]#dhk24u.com',
    'db'   => 'myclassstud',
    'host' => 'localhost'
);
 
//import external libs
require( 'vendor/datatables/ssp.class.php' );
 
echo json_encode(
    SSP::simple( $_GET, $stud_details, $db_table, $primaryKey, $stud_data_col )
);

style.css

.dataTables_wrapper .dataTables_paginate .paginate_button {
    color: #4D525B !important;	
    padding: 0.4em 0.8em;
    border: #4D525B 2px solid;;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current, .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    color: #3d3d3d !important;
	background: unset !important;
	border: #4D525B 2px solid !important;
    background-color: #4D525B !important;
	cursor: default;
}
table.dataTable.row-border tbody th, table.dataTable.row-border tbody td, table.dataTable.live-dt tbody th, table.dataTable.live-dt tbody td {
    border: 2px solid #eee;
    border-left: none;
    border-top: none;
}
.dataTables_wrapper select,.dataTables_wrapper input 
{
	border:2px solid #eee;
	padding:0.4em;
}
.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    color: #4D525B !important;
	border-color: #4D525B !important;
    background-color: #4D525B !important;
	background:unset;
}
table.dataTable.stripe tbody tr.odd, table.dataTable.live-dt tbody tr.odd {
    background-color: #3d3d3d;
}
table.dataTable.live-dt tbody tr.even>.sorting_1, table.dataTable.order-column.stripe tbody tr.even>.sorting_1 {
    background-color: #f3f3f3; 
}
table.dataTable.live-dt tbody tr.odd>.sorting_1, table.dataTable.order-column.stripe tbody tr.odd>.sorting_1 {
    background-color: #3d3d3d; 
}
table.dataTable thead th, table.dataTable thead td {
	border: 2px solid #eee;
    border-left: none;
}
table.dataTable.stripe tbody tr.even, table.dataTable.live-dt tbody tr.even {
    background-color: #f3f3f3;
}
.datatables_length{
	padding-bottom: 15px;
}
table.dataTable{
	border-left:2px solid #eee;
}

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Example

I hope you have Got What is Server Side Processing DataTable with PHP and MySQL And how it works.I would Like to have Feed Back From My Blog(Pakainfo.com) readers.Your Valuable Feed Back,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.


Related FAQ

Here are some more FAQ related to this Article:

  1.   DataTables Pagination Server-side Processing using PHP and MySQL
  2.   Laravel 6 return view jQuery ajax request example
  3.   PHP Functions - MY SQL Connects and Global Variable
  4.   PHP AJAX Live Search Box Autocomplete Using MySQL Database
  5.   PHP Laravel 6 Session-Based Flash Message Example
  6.   Angular2 Datatable Pagination, Sorting and Searching
  7.   PHP Ajax Form Validation without page refresh
  8.   how to run codeigniter project in xampp
  9.   Jquery Datatable listing json Server side in Php Mysql and Ajax
  10.   DataTables Column Search Server side processing in PHP