I have a problem, I have to take the domain name from the database, and create a knokpu with which I can sort the database by this domain, that is, if I clicked on the gmail button, then users with gmail should be sorted, if there are yahoo users then when you click on the yahoo button, the sort will also be performed. The problem is that I don't know how to properly associate a button with sorting ... I will be very grateful for your help.
Here is my php code.
<!DOCTYPE html>
<html>
<head>
<title>Display all records from Database</title>
</head>
<body>
<h2>All emails</h2>
<table border="2">
<tr>
<td>Sr.No.</td>
<td>E-mail</td>
<td>Delete</td>
<td>CSV</td>
</tr>
<a href="?orderBy=email">
<button>Sort By E-mail</button>
</a>
<a href="?orderBy=date">
<button>Sort By Date</button>
</a>
<a href="?orderBy=">
<button>Export as CSV</button>
</a>
</br>
<?php
include "php/server.php"; // Using database connection file here
$orderBy = array('email', 'date'); // create array of sort options
$order='date'; // default sort option
if (isset($_GET['orderBy']) && in_array($_GET['orderBy'], $orderBy)) {
$order = $_GET['orderBy'];
} // change sort option depending on $order
$query = 'SELECT * FROM users ORDER BY '.$order;
$records = mysqli_query($db, $query); // fetch data from database
$dom=array();
include "php/search.php"; //include search engine
if(isset($_POST["submit"])){ //if button is pressed fecth data from search
$records = mysqli_query($db, $searchquery);
}else{ //if not fecth data from db
$records = mysqli_query($db, $query);
}
while($data = mysqli_fetch_array($records))
{
$parts = explode('@', $data['email']);
$domain = array_pop($parts);
?>
<tr>
<td><?php echo $data['email']; ?></td>
<td><?php echo $data['date']; ?></td>
<td><a href="php/delete.php?id=<?php echo $data['id']; ?>">Delete</a></td>
<td><a><input type="checkbox" id="horns" name="horns"></td>
<td><?php echo $domain; ?></td>
</tr>
<tr>
<input type="submit" name="<?php $domain; array_push($dom,$domain)?>" value="<?php echo $domain; ?>">
</tr>
<?php
}
var_dump($dom);
?>
<h3>Emails is sorting by:<?php echo $order ?></h3>
</table>
</body>
</html>
Design: