--
-- Table structure for table `product`
--
CREATE TABLE `product` (
`pid` int(11) NOT NULL,
`name` varchar(70) DEFAULT NULL,
`image` varchar(255) NOT NULL,
`category` varchar(70) DEFAULT NULL,
`price` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Dumping data for table `product`
--
INSERT INTO `product` (`pid`, `name`, `image`, `category`, `price`) VALUES
(1, 'Samsung Galaxy A10S', '1.jpg', 'Mobile', 520),
(2, 'HP Laptop - 17z-ca100 ', '2.jpg', 'Laptop', 1600),
(3, '3 IN 1 CAR VOLTMETER', '3.jpg', 'Car', 2020),
(4, 'Gucci G-Timeless', '4.jpg', 'Watch', 320),
(5, 'Infinix Hot S3', '5.jpg', 'Mobile', 150),
(6, 'VIVO V9 Youth', '6.jpeg', 'Laptop', 3500),
(7, 'Moto E4 Plus', '7.jpeg', 'Car', 250),
(8, 'Lenovo K8 Plus', '8.jpeg', 'Watch', 4500);
--
-- Indexes for dumped tables
--
--
-- Indexes for table `product`
--
ALTER TABLE `product`
ADD PRIMARY KEY (`pid`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `product`
--
ALTER TABLE `product`
MODIFY `pid` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;
Jqueryui Slider https://jqueryui.com/slider/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | //index.php <!DOCTYPE html> <html> <head> <title>Product Filters Price Range Using PHP Mysql and Jquery Ajax</title> </head> <body> <div class = "container" > <div class = "row" > <br /> <h2 align= "center" >Product Filters Price Range Using PHP Mysql and Jquery Ajax</h2> <br /> <div class = "col-md-3" > <div class = "list-group" > <h3>Price</h3> <input type= "hidden" id= "hidden_minimum_price" value= "0" /> <input type= "hidden" id= "hidden_maximum_price" value= "65000" /> <p id= "price_show" >10 - 5000</p> <div id= "price_range" ></div> </div> </div> <div class = "col-md-9" > <br /> <div class = "row filter_data" > </div> </div> </div> </div> <style> #loading{text-align:center; background: url( 'images/loading.gif' ) no-repeat center; height: 150px;} </style> <script> $(document).ready( function (){ filter_data(); function filter_data() { $( '.filter_data' ).html( '<div id="loading" style="" ></div>' ); var action = 'fetch_data' ; var minimum_price = $( '#hidden_minimum_price' ).val(); var maximum_price = $( '#hidden_maximum_price' ).val(); $.ajax({ url: "fetch_data.php" , method: "POST" , data:{action:action, minimum_price:minimum_price, maximum_price:maximum_price}, success: function (data){ $( '.filter_data' ).html(data); } }); } $( '#price_range' ).slider({ range:true, min:50, max:5000, values:[50, 5000], step:50, stop: function (event, ui) { $( '#price_show' ).html(ui.values[0] + ' - ' + ui.values[1]); $( '#hidden_minimum_price' ).val(ui.values[0]); $( '#hidden_maximum_price' ).val(ui.values[1]); filter_data(); } }); }); </script> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | //fetch_data.php <?php include ( 'dbcon.php' ); if (isset( $_POST [ "action" ])) { $query = $conn ->query( "SELECT * FROM product" ); if (isset( $_POST [ "minimum_price" ], $_POST [ "maximum_price" ]) && ! empty ( $_POST [ "minimum_price" ]) && ! empty ( $_POST [ "maximum_price" ])) { $query = $conn ->query( "SELECT * FROM product WHERE price BETWEEN '" . $_POST [ "minimum_price" ]. "' AND '" . $_POST [ "maximum_price" ]. "'" ); } $total_row = mysqli_num_rows( $query ); $output = '' ; if ( $total_row > 0){ while ( $row = $query ->fetch_object()) { $output .= ' <div class = "col-sm-4 col-lg-3 col-md-3" > <div style= "border:1px solid #ccc; border-radius:5px; padding:16px; margin-bottom:16px; height:320px;" > <img src= "images/'. $row->image .'" alt= "" class = "img-responsive" > <p align= "center" ><strong><a href= "#" > '. $row->name .' </a></strong></p> <h4 style= "text-align:center;" class = "text-danger" > '. $row->price .' </h4> </div> </div>'; } } else { $output = '<h3>No Data Found</h3>' ; } echo $output ; } ?> |
1 2 3 4 5 6 7 | //dbcon.php <?php $conn = new mysqli( 'localhost' , 'root' , '' , 'testingdb' ); if ( $conn ->connect_error) { die ( 'Error : (' . $conn ->connect_errno . ') ' . $conn ->connect_error); } ?> |