View Single Post
Old 02-03-2013, 03:45 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Okay, this is really 90% a PHP question and only 10% MySQL.

And I don't use PHP. So bear with me if I make a couple of PHP typos.
Code:
<!-- don't use PHP to write out large blocks of HTML -->
<!-- makes it harder to read, harder to write, and tiny bit slower -->
<table border="1"' cellpadding="10">; 
<tr>
    <th><a href="thispage.php?by=nameLast">Last Name</a></th>
    <th><a href="thispage.php?by=nameFirst">First Name</a></th>
</tr>
<?php
// make you db connection here ...

$orderby = $_GET["by"];
if ( ! isset($orderby) || ( $orderby != "nameLast" && $orderby != "nameFirst" ) ) 
{
    $orderby = "nameLast"; // or whatever default you choose
}

// get results from database 
$result = mysql_query("SELECT * FROM mytable ORDER BY $orderby ")  
                or die(mysql_error());   

... rest the same ...
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
Eggweezer (02-03-2013)