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=department&disposition=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

Reply via email to