If you wish to implement easy but simple reordering functionality, turn your table headers into links with
printf('<a href="?orderby=%s">%s</a>',
urlencode($orderby),
htmlspecialchars($orderby, ENT_QUOTES, 'utf-8')
);
And then in the script for that page, add
$ok_orderby = array('Date', 'First', 'Last');
# First line: check if orderby is set,
# Second line: check that it doesn't contain any crap it shouldn't
if (!isset($_GET['orderby']) ||
!in_array($_GET['orderby'])
{
# Default sorting
$orderby = 'Date';
}
else
{
$orderby = $_GET['orderby'];
}
# Always specify the columns you select, never use *
$query = sprintf('SELECT First, Last, Date FROM logs ORDER BY %s',
$orderby
);
# Don't use mysql_query. It's been deprecated a long time ago.
# Switch to the mysqli_* functions, or use PDO instead.
mysql_query(...)
If you want the table to be sortable without sending a new page request, you'd have to find a javascript library which handles HTML tables to make them sortable, such as tablesorter 2.0 for jQuery. Well, either that or code it yourself.