When I click one of the arrows to sort search results returned to page
it reloads the entire original query, instead of sorting the search
results. I think it has something to do with
HREF="<?=$PHP_SELF?>?order=acct">.
When search results are returned, it looks like this
http://www.someurl.com/xx.php?keyword=d&where=3&submit=Search
when I try to sort the results, it returns the orignal displayd sql
query but sorted.
http://www.someurl.com/xx.php?order=acct&way=desc
What is wrong with my script? Please see below snippet. Thanks in advance
<?
/ set the allowed order by columns /
$default_sort = 'acct';
$default_way ='asc';
$allowed_order = array ('acct',
'lname','mkval');
/ if order is not set, or it is not in the allowed
list, then set it to a default value.
Otherwise,
set it to what was passed in. /
if (!isset ($GET['order']) ||
!in_array ($GET['order'], $allowed_order)) {
$order = $default_sort;
$way = $default_way;
} else {
$order = $GET['order'];
$way= $GET['way'];
}
// get a list of accounts the user has permission for
$connection = mysql_connect($hostname, $user, $pass) or die ("Unable
to connect!");
$query = "SELECT files.id, files.acct, files.doc_date, files.file,
files.rep_id, files.mgr_id, files.lname, files.mkval, files.dir FROM
files WHERE files.rep_id = '$SESSION_UID'";
// this page also serves as the "search results" page
// if coming from the search form, $keyword and $where will
exist
// so modify the query with additional constraints
if ($keyword != "" && isset($where))
{
// switch loop
switch ($where)
{
// description search
case 1:
$query .= " AND (files.acct LIKE '%$keyword%')";
break;
// filename search
case 2:
$query .= " AND (files.lname LIKE '%$keyword%')";
break;
// search all!
case 3:
$query .= " AND (files.acct LIKE '%$keyword%' OR
files.lname LIKE '%$keyword%')";
break;
}
}
$query .= " ORDER BY $order $way";
$result = mysql_db_query($database, $query, $connection) or die
("Error in query: $query. " . mysql_error());
$count = mysql_num_rows($result);
?>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td bgcolor="#0000A0" align="left"><b><font face="Arial"
color="White"><? echo $count; ?> account(s) found click on account
number to view statement</b></td>
</tr>
</table>
<p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" width="100"> <A
HREF="<?=$PHP_SELF?>?order=acct"><IMG
SRC="images/arrow_up.jpg"border="0"></a><b>Account</b><A
HREF="<?=$PHP_SELF?>?order=acct&way=desc"><IMG
SRC="images/arrow_down.jpg"border="0"></a></td>
<td align="left" width="225"> <A
HREF="<?=$PHP_SELF?>?order=lname"><IMG
SRC="images/arrow_up.jpg"border="0"></a><b>Account Name</b><A
HREF="<?=$PHP_SELF?>?order=lname&way=desc"><IMG
SRC="images/arrow_down.jpg"border="0"></a></td>
<td align="center" width="150"><b>Statement Date </b></td>
<td align="center" width="150"> <A
HREF="<?=$PHP_SELF?>?order=mkval"><IMG
SRC="images/arrow_up.jpg"border="0"></a><b>Market Value</b><A
HREF="<?=$PHP_SELF?>?order=mkval&way=desc"><IMG
SRC="images/arrow_down.jpg"border="0"></a></td>
</tr>
</table>
<hr>
<?