This switch case runs sortable columns for me.
So, my problem is that when the page loads for the first time,
it loads the first switch case instead of the default.
I've tested this by changing the parameters,
so I know the default gets skipped, even though it looks
like it wouldn't make a difference.
Any ideas?
<td bgcolor="F9FBF0">Client Name <a href="viewClients.php?sort=1">asc</a> |
<a href="viewClients.php?sort=2">desc</a></td>
<td bgcolor="F9FBF0"> <a href="viewClients.php?sort=3">Client Phone</a></td>
<td width="150" bgcolor="F9FBF0"> <a href="viewClients.php?sort=4">Client Email</a></td>
<td width="50" align="center" bgcolor="F9FBF0">Edit</td>
<td width="50" align="center" bgcolor="F9FBF0">Delete</td>
</tr>
<tr class="listContent">
<?php
$username = "cpoint";
$password = "*****";
$database = "counterpoint";
$link = mysql_connect( "localhost", $username, $password );
if ( ! $link ) {
$dberror = "Couldn't connect to MySQL server.";
return false;
}
if ( ! mysql_select_db( $database, $link ) ) {
$dberror = mysql_error();
return false;
}
if ($_GET['sort']) {
$orderQuery = " ORDER BY ";
switch ($_GET['sort']) {
case "1":
$orderQuery .= "clientname ASC";
break;
case "2":
$orderQuery .= "clientname DESC ";
break;
case "3":
$orderQuery .= "phone ";
break;
case "4":
$orderQuery .= "email ";
break;
default:
$orderQuery .= "clientname ASC ";
break;
}
}
$data = mysql_query( "SELECT clientname, phone, email FROM clients" . $orderQuery );
thanks!