A little bit of AJAX can make this a re-sortable output. As you can see from the following example, it's not that difficult.
The below code will put a drop-down on the page, and allow the user to choose sort order. Upon choosing, the sorted results will appear in the div. The user can then choose a different sort order, and those results will appear in the div.
HTML:
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#mysel').change(function() {
var sby = $(this).val();
//alert(sby);
$.ajax({
type: "POST",
url: "another_php_file.php",
data: 'sortby=' + sby,
success: function(thedata) {
$("#results").html(thedata) ;
}
});
});
}); //END $(document).ready()
</script>
</head>
<body>
<div id="results"></div>
<select id="mysel">
<option value = '0'>Choose One</option>
<option value = 'last'>Sort by Last Name</option>
<option value = 'first'>Sort by First Name</option>
</select>
</body>
</html>
another_php_file.php
<?php
$order = $_POST['sortby'];
// Do your database login here
$output = '<table><tr><td>ID</td><td>Name</td><td>Email</td></tr>';
$result = mysql_query("SELECT * FROM contacts WHERE type = 'lead' ORDER BY '$order'");
$num_rows = mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)) {
$output .= '<tr>';
$output .= '<td>' . $row['id'] . '</td>';
$output .= '<td>' . $row['name'] . '</td>';
$output .= '<td>' . $row['email'] . '</td>';
$output .= '<td>' . '<a href = "/admin/leads/convert-contact.php?id=' . $row[id] . '">Make Contact</a>';
$output .= '</tr>';
}
$output .= '</table>';
echo $output;
If you are new to AJAX, here are some very simple examples to give you the hang of it. They are well worth the 15 or 20 mins to play around with.
A simple example
More complicated example
Populate dropdown 2 based on selection in dropdown 1