Web Analytics Made Easy -
StatCounter Need Help w/ sorting columns in table - CodingForum

Announcement

Collapse
No announcement yet.

Need Help w/ sorting columns in table

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need Help w/ sorting columns in table

    Hello I could use some help, I would like to be able for a viewer to click on (Description Location Deadline) and have it sort, I can't get it to work, any help would be greatly appreciated. Thank You


    http://www.darlington.k12.sc.us/dcsd...ment/oview.php



    <?php
    $query = "SELECT id, location, description, syear FROM teacher ORDER BY description;";
    $result = mysql_query($query,$link);
    print "<table border=\"1\">";
    print "\t<b><tr><td>Description</td><td>Location</td><td>School Year</td></tr><tr></b>\n";
    while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
    {
    print "\t\t<td><font size=\"-1\"><a href=\"tpopup.php?id=$line[id]\" target=\"_blank\">$line[description]</a></td>\n";
    print "\t\t<td><font size=\"-1\"><a href=\"http://www.darlington.k12.sc.us/dcsdweb/general/Location/location.html\" target=\"_blank\">$line[location]</a></td>\n";
    print "\t\t<td><font size=\"-1\">$line[syear]</a></td>\n";
    print "\t</tr>\n";
    }
    print "</table>\n";
    ?>
    Last edited by Za_Claw; Feb 13, 2004, 03:43 PM.

  • #2
    My g/f works for Horry County school district. She might get mad at me if I help someone from another competing district.

    If I were you though I would probably do it something along these lines:

    PHP Code:

    <?php

    $orderby 
    $_GET['orderby'];
    $query "SELECT id, location, description, syear FROM teacher ORDER BY "$orderby;
    $result mysql_query($query,$link);

    ?>

    <table border="1">
    <tr><td><a href="<?php echo $_SERVER['PHP_SELF'] ; ?>?orderby=description">Description</a></td><td><a href="<?php echo $_SERVER['PHP_SELF'] ; ?>?orderby=location">Location</td><td><a href="<?php echo $_SERVER['PHP_SELF'] ; ?>?orderby=syear">School Year</td></tr>

    <?php
    while($line mysql_fetch_array($result)){
        
    //code to print out the contents of the table
    }
    ?>

    <table>
    Avoid printing out everything using PHP. It just gets messy. Only print what you need PHP to print. Doing it this way makes the headers of the table hyperlinked to the same page and allows it to modify the query and sort the data during the query by the column specified in the table header.
    Spookster
    CodingForum Supreme Overlord
    All Hail Spookster

    Comment


    • #3
      but spook, i work for amherst county school district in va...doesn't that count???

      Comment


      • #4
        Originally posted by Celtboy
        but spook, i work for amherst county school district in va...doesn't that count???
        Not until I move there, which should be in the next few weeks.
        Spookster
        CodingForum Supreme Overlord
        All Hail Spookster

        Comment

        Working...
        X