class1=$("input[name=r1]:checked").val()
This data ( about the class selection by user ) is stored in a variable and same is passed to our backend script loadck.php file using load() function.
$('#d').load('loadck.php?class='+class1);
Here is the complete JQuery code.
<script>
$(document).ready(function() {
// Jquery code here ///
$("input[type='radio']").change(function() {
class1=$("input[name=r1]:checked").val()
$('#d').load('loadck.php?class='+class1);
});
///
});
</script>
With this code our data in terms of selection of user ( from class three to class Nine ) will be passed to backend PHP script loadck.php. Inside this loadck.php first we will collect the filter data posted from our front end JQuery code.
$class=$_GET['class']; // collect the student class
This variable $class
will be used in our PHP script to filter the rows from MySQL table using PDO database connection.
The code for our backend PHP script is here.
<?Php
require "config.php"; // database connection details
///////////////////////////////////////////
$class=$_GET['class']; // collect the student class
//$str='Four';
$query="SELECT * FROM student WHERE class=:class";
$step = $dbo->prepare($query);
$step->bindParam(':class', $class,PDO::PARAM_STR,50);
$step->execute();
$step = $step->fetchAll();
echo "
<table class='table table-striped'> <tr class='table-primary'><th>ID</th>
<th>NAME</th><th>CLSS</th><th>MARK</th></tr>";
foreach ($step as $row) {
echo "<tr ><td>$row[id]</td><td>$row[name]</td>
<td>$row[class]</td><td>$row[mark]</td></tr>";
}
echo "</table>";
?>
Most Popular JQuery Scripts | |
1 | Two dependant list boxes |
2 | Calendar with Date Selection |
3 | Data change by Slider |
4 | Show & Hide element |