John Nikko Cruz John Nikko Cruz - 5 months ago 8
PHP Question

How can i change the content a table tag in html with values retrieved from database upon filtering it with buttons

I am trying to change the data fetched by mysql in a table tag when a button is click. It's like filtering the data in the table by active and inactive

Answer

You could send a get request and pass a value to it to filter:

<?php
$age=""
if(isset($_GET["age"])){
$age=htmlspecialchars($_GET["age"]);
}
$query="SELECT ... FROM ... WHERE age='$age'";
//run query + output
?>

Use this link to filter

<a href="?age=18">Just show 18 year old</a>

Or this form:

<form action="thissite.php" method="get">
<select name="age" id="age">
<option value="18">18</option>
...
</select>
<button type="submit">Filter</button>
</form>