+ Reply to Thread
Results 1 to 2 of 2

Thread: PHP: Sort items at command?

  1. #1
    ChiBuki is offline x10Hosting Member ChiBuki is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    11

    PHP: Sort items at command?

    Hi! I want to try something new with this table.

    By default it's sorted by ID descending. The command:
    PHP Code:
    $query "SELECT ID, FeaturedCharacter, Rank, Average, TotalVotes, FivePoints, FourPoints, ThreePoints, TwoPoints, OnePoints, DateUpdated, Poll FROM TsundereOrNot ORDER BY ID DESC LIMIT $offset$rowsPerPage"
    I want to make the table headers to be clickable. When I click on "Character", the table should be sorted by the character's name alphabetically. When I click on "Last Updated", the table should be sorted by the last updated date, and so on.... And when I click on "Average", the table should be sorted from the highest number to lowest; but when I click on "Average" again, it would sort from lowest to highest.

    Basically I want it to be exactly like this, where you can have the list sorted by whatever is clicked in the table header.

    How do I make my table be like that using PHP?

    I didn't have luck with finding tutorials on Google, probably because I don't know the keyword/term for it. Thanks. :happysad:

  2. #2
    xmakina's Avatar
    xmakina is offline x10 Lieutenant xmakina is an unknown quantity at this point
    Join Date
    May 2008
    Location
    England
    Posts
    265

    Re: PHP: Sort items at command?

    Easily.

    (this is lifted from my own site so you'll have to change it to fit your own)

    Build your SQL query then
    PHP Code:
        if($_GET['sortBy'] != null){
            
    $sql .= " ORDER BY " $_GET['sortBy'];
        } else {
            
    $sql .= " ORDER BY BandList.gigDate";
        } 
    And at the top of your table put:
    PHP Code:
    echo "<tr>";
                echo 
    "<th><a href=\"?sortBy=bandName\">Band</a></th>";
                echo 
    "<th><a href=\"?sortBy=tourName\">Tour</a></th>";
                echo 
    "<th><a href=\"?sortBy=venueName\">Venue</a></th>";
                echo 
    "<th><a href=\"?sortBy=townName\">Town</a></th>";
                echo 
    "<th><a href=\"?sortBy=gigDate\">Date</a></th>";
                echo 
    "<th><a href=\"?sortBy=attending DESC\">Attending?</a></th>";
                echo 
    "<th>Buy Tickets</th>";
            echo 
    "</tr>"
    IF($this->$post.content() == "SEE SIG"){
    w3Schools and Google
    }

+ Reply to Thread

Similar Threads

  1. Ever Been Suspended For Using PHP?
    By dragoneye_xp in forum Off Topic
    Replies: 26
    Last Post: 08-16-2009, 07:17 PM
  2. PHP and new accounts
    By idani in forum Free Hosting
    Replies: 1
    Last Post: 09-21-2008, 01:49 PM
  3. currently have an application pending php
    By biomasti in forum Free Hosting
    Replies: 1
    Last Post: 09-03-2008, 01:58 PM
  4. Important PHP Information
    By Bryon in forum News and Announcements
    Replies: 0
    Last Post: 11-21-2007, 02:08 PM
  5. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers