Hi Guys today I am giving this tutorial for client side searching in a PHP with jQuery Datatable Plugin this is a very plain and smooth code so you can use it. you can use this code your website and projects where you want to use rapid searching you can use this code it is 5 line of code to create a plain and rapid searching so check it in below.
First of all you should add .CSS file and .JS file and Jquery file in your php file.
CDN CSS file
........................
http://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css
CDN Jquery file
........................
https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js
CDN JS file
........................
http://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js
Example here :
<?php
$obj=new mysqli("localhost","root","","database_name");
?>
<html>
<head>
<title>Demo Live search and pagination</title>
<link rel="stylsheet" type="text/css" href="http://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="http://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
</head>
<body>
<table id="tableId" class="display" cellspacing="1" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
<tbody>
<?php
$sl="select * from table";
$qq=$obj->query($sl);
while($ff=$qq->fetch_object())
{
?>
<tr>
<td><?php echo $ff->name; ?></td>
<td><?php echo $ff->position; ?></td>
<td><?php echo $ff->office; ?></td>
<td><?php echo $ff->age; ?></td>
<td><?php echo $ff->srt_date; ?></td>
<td><?php echo $ff->salary; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</body>
</html>
<script>
$(document).ready(function(){
$('#tableId').DataTable();
});
</script>

Comments
Post a Comment