RE: [PHP] Simple table sorting

2003-12-03 Thread Luis Lebron
You may want to also try a javascript solution

See http://www.kryogenix.org/code/browser/sorttable/ for an example.

Luis


-Original Message-
From: Tommi Virtanen [mailto:[EMAIL PROTECTED]
Sent: Tuesday, December 02, 2003 8:30 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Simple table sorting


Hi!

I have simple table like:

namedepartment
[data: first name]  [data: dep. no]
[data: second name] [data: dep. no]

Now I have only sorting which sorts using ORDER BY name. How I
make header name / department active link, which I can change sorting
order Department and then back to Name?

regards,

gustavus

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Simple table sorting

2003-12-02 Thread Robert Cummings
On Tue, 2003-12-02 at 21:30, Tommi Virtanen wrote:
 Hi!
 
 I have simple table like:
 
 name  department
 [data: first name][data: dep. no]
 [data: second name]   [data: dep. no]
 
 Now I have only sorting which sorts using ORDER BY name. How I
 make header name / department active link, which I can change sorting
 order Department and then back to Name?

If you mean so that the user can click the department column heading
and have the data sorted by department, then you can create a link to
the current page with url parameters orderBy and disposition. For
instance:

myPage.php?orderBy=departmentdisposition=ascending

Then in your page you can check the values of these and modify the
ORDER BY clause of your query. The following example exemplifies what
I'm saying:

 $qString =
SELECT 
   .   name, 
   .   department 
   .FROM 
   .   foo_table 
   .ORDER BY ;

if( isset( $_GET['orderBy'] )

$_GET['orderBy'] == 'department' )
{   
$qString .= 'department ';
}
else
{   
$qString .= 'name ';
}  

if( isset( $_GET['disposition'] )

$_GET['disposition'] == 'desc' )
{
$qString .= 'DESC ';
}
else
{
$qString .= 'ASC ';
}
 
mysql_query( $qString );
   
HTH,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php