SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Sep 2001
    Location
    Vancouver
    Posts
    809
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sort By Columns Help

    I need some help creating links that sort the table by the column that the person clicked on. For example if you do a search on Cnet.com in the downloads section, you can click on the name, date, size, etc... to sort them by that.

    How would I go about doing that in my columns? Is there a fixed link, that I just need to edit to suit my needs?

    Any help would be greatly appreciated!

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's usually sort of like this (rough, non-working example):

    PHP Code:
    <?php
      
    if ($sort == "name") {
        
    $field "username";
      } else if (
    $sort == "date") {
        
    $field "date";
      } else {
        
    $field "title";
      }

    $result mysql_result("SELECT blah FROM table WHERE blah ORDER BY $field DESC");
    That's the basic logic behind it. You pass the field to sort by (or a word that lets you know what field to sort by) in the URL with the link, and modify your query accordingly.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •