Announcement

Collapse
No announcement yet.

SORTABLE columns

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

  • SORTABLE columns

    Basically I am printing out the data of my db, and now I want to make certain columns sortable...please help me.

    URL -

    http://www.restorekids.com/wreed/new...ayerstats3.php

    WHEN I CLICK on the COLUMN to sort the players names it does NOT sort...any ideas...help!

    PHP Code:
    <? 
    $connection 
    mysql_connect("localhost","*******","******"); 
    $db mysql_select_db("restore_stats"$connection); 
    $sql mysql_query("SELECT * FROM `players` WHERE 1"); 
    If (
    $HTTP_GET_VARS["sort"] = "players") {$SQL mysql_query("SELECT * FROM `players` WHERE 1 ORDER BY `player` ASC");} 
    If (
    $HTTP_GET_VARS["sort"] = "team") {$SQL mysql_query("SELECT * FROM `players` WHERE 1 ORDER BY `Team` DESC");} 
    If (
    $HTTP_GET_VARS["sort"] = "position") {$SQL mysql_query("SELECT * FROM `players` WHERE 1 ORDER BY `Position` DESC");} 
    echo 
    "<tr> 
    <td bgcolor=gray><a href='playerstats3.php?sort=players'>Name</a></td> 
    <td bgcolor=gray align=center><a href='playerstats3.php?sort=team'>Team</a></td> 
    <td bgcolor=gray align=center>Jersey #</td> 
    <td bgcolor=gray align=center><a href='playerstats3.php?sort=pos'>Posistion</a></td> 
    <td bgcolor=gray align=center>Games</td> 
    <td bgcolor=gray align=center>Goals</td> 
    <td bgcolor=gray align=center>Assist</td> 
    <td bgcolor=gray align=center>Points</td> 
    <td bgcolor=gray align=center>PIMs</td> 
    <td bgcolor=gray align=center>+/-</td> 
    <td bgcolor=gray align=center>PPG</td> 
    <td bgcolor=gray align=center>SHG</td> 
    <td bgcolor=gray align=center>GWG</td> 
    <td bgcolor=gray align=center>Shots</td> 
    <td bgcolor=gray align=center>Shot %</td> 
    <td bgcolor=gray align=center>FOW</td> 
    <td bgcolor=gray align=center>FOT</td> 
    <td bgcolor=gray align=center>GV</td> 
    <td bgcolor=gray align=center>TK</td> 
    <td bgcolor=gray align=center>Min</td> 
    <td bgcolor=gray align=center>Hits</td> 
    <td bgcolor=gray align=center>Height</td> 
    <td bgcolor=gray align=center>Weight</td> 
    <td bgcolor=gray align=center>Shoots</td> 
    </tr>"

    $alternate "2"
    while (
    $row mysql_fetch_array($sql)) { 
    $player $row["player"]; 
    $team $row["team"]; 
    $jersey $row["jersey"]; 
    $pos $row["pos"]; 
    $games $row["games"]; 
    $goals $row["goals"]; 
    $assists $row["assists"]; 
    $points $row["points"]; 
    $pim $row["pim"]; 
    $plusminus $row["plusminus"]; 
    $ppg $row["ppg"]; 
    $shg $row["shg"]; 
    $gwg $row["gwg"]; 
    $shots $row["shots"]; 
    $shotpct $row["shotpct"]; 
    $fow $row["fow"]; 
    $fot $row["fot"]; 
    $gv $row["gv"]; 
    $tk $row["tk"]; 
    $min $row["min"]; 
    ****
    $row["hits"]; 
    $height $row["height"]; 
    $weight $row["weight"]; 
    $shoots $row["shoots"]; 

    if (
    $alternate == "1") { 
    $color "#ffffff"
    $alternate "2"

    else { 
    $color "#c0c0c0"
    $alternate "1"

    echo 
    "<tr bgcolor=$color><td>$player</td> 
    <td align=center>
    $team</td> 
    <td align=center>
    $jersey</td> 
    <td align=center>
    $pos</td> 
    <td align=center>
    $games</td> 
    <td align=center>
    $goals</td> 
    <td align=center>
    $assists</td> 
    <td align=center>
    $points</td> 
    <td align=center>
    $pim</td> 
    <td align=center>
    $plusminus</td> 
    <td align=center>
    $ppg</td> 
    <td align=center>
    $shg</td> 
    <td align=center>
    $gwg</td> 
    <td align=center>
    $shots</td> 
    <td align=center>
    $shotpct</td> 
    <td align=center>
    $fow</td> 
    <td align=center>
    $fot</td> 
    <td align=center>
    $gv</td> 
    <td align=center>
    $tk</td> 
    <td align=center>
    $min</td> 
    <td align=center>****s</td> 
    <td align=center>
    $height</td> 
    <td align=center>
    $weight</td> 
    <td align=center>
    $shoots</td></tr>"


    echo 
    "</table>"

    ?>
    Last edited by Horizon022; Wed 3 Apr '02, 9:54am.
    http://www.redhat.com/img/powered_by_t.gif

  • #2
    Does this even work at all??

    $SQL = mysql_query(
    while ($row = mysql_fetch_array($sql)) {

    one is all caps, the other all lower....

    Comment


    • #3
      Re: SORTABLE columns

      Originally posted by Horizon022
      PHP Code:
      If ($HTTP_GET_VARS["sort"] = "players") {$SQL mysql_query("SELECT * FROM `players` WHERE 1 ORDER BY `player` ASC");} 
      If (
      $HTTP_GET_VARS["sort"] = "team") {$SQL mysql_query("SELECT * FROM `players` WHERE 1 ORDER BY `Team` DESC");} 
      If (
      $HTTP_GET_VARS["sort"] = "position") {$SQL mysql_query 
      [/B]
      in your if statements, you are using the assignment operator (=) instead of the comparison operator (==). I think you wanted lines like this:
      PHP Code:
      If ($HTTP_GET_VARS["sort"] == "players"

      Comment


      • #4
        Thanks guys, I must say I am totally new at PHP and I know I have syntax problems...hey this is done with one week of php, everything except the http statements......well from phpbuilder.com someone helped me greatly, rewrote my whole code. Are you guys interested in seeing the code?
        http://www.redhat.com/img/powered_by_t.gif

        Comment

        Related Topics

        Collapse

        Working...
        X