In this tutorial list records from the MySQL database table and filter the list on salary basis using the slider widget.
jQuery UI slider. https://jqueryui.com/slider/
CREATE TABLE `employee` (
`id` int(11) NOT NULL,
`name` varchar(100) NOT NULL,
`position` varchar(100) NOT NULL,
`office` varchar(100) NOT NULL,
`age` int(11) NOT NULL,
`salary` int(11) NOT NULL,
`photo` varchar(150) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `employee` (`id`, `name`, `position`, `office`, `age`, `salary`, `photo`) VALUES
(1, 'Tiger Wood', 'Accountant', 'Tokyo', 36, 5689, '01.jpg'),
(2, 'Mark Oto Ednalan', 'Chief Executive Officer (CEO)', 'London', 56, 5648, '02.jpg'),
(3, 'Jacob thompson', 'Junior Technical Author', 'San Francisco', 23, 5689, '03.jpg'),
(4, 'cylde Ednalan', 'Software Engineer', 'Olongapo', 23, 54654, '04.jpg'),
(5, 'Angelica Ramos', 'Software Engineer', 'San Francisco', 26, 5465, '05.jpg'),
(6, 'Airi Satou', 'Integration Specialist', 'New York', 53, 56465, '06.jpg'),
(8, 'Tiger Nixon', 'Software Engineer', 'London', 45, 456, '07.jpg'),
(9, 'Airi Satou', 'Pre-Sales Support', 'New York', 25, 4568, '08.jpg'),
(10, 'Angelica Ramos', 'Sales Assistant', 'New York', 45, 456, '09.jpg'),
(11, 'Ashton updated', 'Senior Javascript Developer', 'Olongapo', 45, 54565, '01.jpg'),
(12, 'Bradley Greer', 'Regional Director', 'San Francisco', 27, 5485, '02.jpg'),
(13, 'Brenden Wagner', 'Javascript Developer', 'San Francisco', 38, 65468, '03.jpg'),
(14, 'Brielle Williamson', 'Personnel Lead', 'Olongapo', 56, 354685, '04.jpg'),
(15, 'Bruno Nash', 'Customer Support', 'New York', 36, 65465, '05.jpg'),
(16, 'cairocoders', 'Sales Assistant', 'Sydney', 45, 56465, '06.jpg'),
(17, 'Zorita Serrano', 'Support Engineer', 'San Francisco', 38, 6548, '07.jpg'),
(18, 'Zenaida Frank', 'Chief Operating Officer (COO)', 'San Francisco', 39, 545, '08.jpg');
ALTER TABLE `employee`
ADD PRIMARY KEY (`id`);
ALTER TABLE `employee`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=19;
//templates/index.php <!doctype html> <html> <head> <title>How to use jQuery UI slider to filter records using Jquery Ajax and PHP mysql</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" /> <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <script type='text/javascript'> $(document).ready(function(){ // Initializing slider $( "#slider" ).slider({ range: true, min: 100, max: 360000, values: [ 100, 360000 ], slide: function( event, ui ) { // Get values var min = ui.values[0]; var max = ui.values[1]; $('#range').text(min+' - ' + max); // AJAX request $.ajax({ url: 'getData.php', type: 'post', data: {min:min,max:max}, success: function(response){ // Updating table data $('#emp_table tr:not(:first)').remove(); $('#emp_table').append(response); } }); } }); }); </script> </head> <body > <div class="container" > <div class="row" style="padding:50px;"> <p><h1>How to use jQuery UI slider to filter records using Jquery Ajax and PHP mysql</h1></p> <!-- slider --> <div id="slider"></div><br/> Range: <span id='range'></span> <table id='emp_table' class="table table-hover" width='100%'> <tr> <th>Name</th> <th>Position</th> <th>Office</th> <th>Salary</th> </tr> <?php include "dbcon.php"; $query = $conn->query("select * from employee order by name asc"); while ($row = $query ->fetch_object()) { $fullname = $row->name; $position = $row->position; $office = $row->office; $salary = $row->salary; $salaryformat = number_format($salary); ?> <tr> <td><?php echo $fullname; ?></td> <td><?php echo $position; ?></td> <td><?php echo $office; ?></td> <td>$ <?php echo $salaryformat; ?></td> </tr> <?php } ?> </table> </div> </div> </body> </html>templates/getData.php
//templates/getData.php <?php include('dbcon.php'); $min = $_POST['min']; $max = $_POST['max']; $query = $conn->query("select * from employee where salary>=$min and salary<=$max"); $html = ''; while ($row = $query ->fetch_object()) { $fullname = $row->name; $position = $row->position; $office = $row->office; $salary = $row->salary; $salaryformat = number_format($salary); $html .='<tr>'; $html .='<td>'.$fullname.'</td>'; $html .='<td>'.$position.'</td>'; $html .='<td>'.$office.'</td>'; $html .='<td>$ '.$salaryformat.'</td>'; $html .='</tr>'; } echo $html;templates/dbcon.php
//templates/dbcon.php <?php $conn = new mysqli('localhost','root','','testingdb'); if ($conn->connect_error) { die('Error : ('. $conn->connect_errno .') '. $conn->connect_error); } ?>