Question: "Click to sort" table headings...

Codes here !

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 80
Joined: Fri Jan 31, 2003 4:18 pm

Mon Feb 17, 2003 6:51 am

first of you need another GET variable in yur tablename-links

create a variable $sortOrder = "DESC" if it does not exist, otherwise the GET sortorder-variable.

You need to place it in yur query:

Code: Select all

$query .= " ORDER BY $sort_col $sortOrder";

You need to place it in yur link, but it needs to be the ASC if it has sorted it DESC, so make a switch for it

Code: Select all

switch($sortOrder) {
case "ASC":  $sortOrder="DESC"; break;
case "DESC":$sortOrder="ASC"; break;

then place the new sortOrder in yur link:

Code: Select all

printf ("<th><a href=\"%s?sort=%s&sortorder=$sortOrder\">%s</a></th>\n", 
                urlencode ($col_name),
                htmlspecialchars ($col_name));

Post Reply