+ Reply to Thread
Results 1 to 2 of 2

Thread: Mysql and PHP help

  1. #1
    equipemis is offline x10Hosting Member equipemis is an unknown quantity at this point
    Join Date
    Oct 2009
    Posts
    12

    Mysql and PHP help

    Hi guys,

    I have a problem with the current page:

    Code:
     <div id="content">
      <div class="post">
       <h1 class="title">Statistiques</h1>
       <div class="entry">
       <br/><br/><center><a href="complete_stats.php?pos=player&order=points">Statistiques des joueurs</a> | <a href="complete_stats.php?pos=goaler&order=wins">Statistiques des gardiens</a> |
       <a href="rookie_stats.php?pos=player&order=points">Statistiques des recrues</a> | <a href="farm_stats.php?pos=player&order=points">Statistiques des joueurs AHL</a><br/><br/>
    <?php
      error_reporting(0);
      $class = "class='odd'";
      mysql_query("SET CHARACTER SET utf8"); //Set database to unicode
      mysql_query("SET NAMES 'utf8'");
    $type= $_GET['pos'] ;
    $orderg= $_GET['order'] ;
    echo "<br/><br/>";
    if ($type == player)
    {
    $where = "!=1";
    }
    else{
    $where = "=1";
    }
    if ($orderg == goals)
    {
    $order = "`nhl_goals`";
    }
    else if ($orderg == points)
    {
    $order = "`nhl_goals` + `nhl_assists`";
    }
    else if ($orderg == wins)
    {
    $order = "`nhl_wins`";
    }
    else
    {
    $order = "`nhl_shots/saves` / (`nhl_ga` + `nhl_shots/saves`)";
    }
    if ($type == player)
    {
    echo "<table class='sortable'>
    <thead>
      <tr>
       <th>Nom</th>
       <th>&nbsp;</th>
       <th>Pos</th>
       <th>Parties</th>
       <th>Buts</th>
       <th>Assists</th>
       <th>Points</th>
       <th>+/-</th>
       <th>BAN</th>
       <th>BDN</th>
       <th>BV</th>
       <th>M&Eacute;</th>
       <th>%MJ</th>
       <th>Tirs</th>
       <th>%Tirs</th>
       <th>MIP</th>
      </tr>
      </thead>
      <tfoot>
       <tr>
        <th colspan='16'>&nbsp;</th>
       </tr>
      </tfoot>";
    }
    else
    {
    echo "<table class='sortable'>
    <thead>
      <tr>
       <th>Nom</th>
       <th>&nbsp;</th>
       <th>Pos</th>
       <th>Parties</th>
       <th>Vic</th>
       <th>D&eacute;f</th>
       <th>Ot/S</th>
       <th>BC</th>
       <th>MBC</th>
       <th>Ar</th>
       <th>%Ar</th>
       <th>BL</th>
       <th>B</th>
       <th>A</th>
       <th>Pts</th>
      </tr>
      </thead>
      <tfoot>
       <tr>
        <th colspan='15'>&nbsp;</th>
       </tr>
      </tfoot>";
    }
    $link = mysql_connect ("localhost", "", "")
      or die("mysql_error()");
    $result = mysql_query("SELECT * FROM statistics JOIN players ON statistics.playerid = players.id WHERE `main_position` $where ORDER BY $order DESC LIMIT 0,30 ",$link);
    while($row = mysql_fetch_array($result))
        {
        $pos = "" .$row['main_position']. "";
    $get_pos = mysql_query("SELECT * FROM `position`  WHERE `id` = '$pos' ",$link);
    $get_posname = mysql_fetch_array($get_pos) or die(mysql_error());
    $PosName = "" .$get_posname ['Pos']. "";
    $First = substr("$PosName", 0,1);
    $Second = substr("$PosName", 7,1);
    $PosName = "$First$Second";
    $player = "" .$row['name']. "";
    if ($class == "class='odd'") { // this will rotate the value.
           $class = "";
           }else{
           $class = "class='odd'";
       }
    $team = "" .$row['team']. "";
         $get_pteam = mysql_query("SELECT * FROM `teams_numbers`  WHERE `ProId` = '$team' OR `FarmId` = '$team'",$link);
         $get_pname = mysql_fetch_array($get_pteam) or die(mysql_error());
         $PPName = "" .$get_pname ['ProName']. "";
         $team = str_replace(" ", "", $PPName);
    if ($type == player)
    {
    $points = $row['nhl_goals'] + $row['nhl_assists'];
    $p_mj = ($row['nhl_faceoffs_won'] / $row['nhl_faceoffs']) * 100;
    $p_mj = round($p_mj);
    $p_t = ($row['nhl_goals'] / $row['nhl_shots/saves']) * 100;
    $p_t = round($p_t);
    echo "<tr $class><td>" .$row['player_name']. "</td>";
    echo "<td><img src='../images/logos/$team.png' width='40' height='20'/></td>";
    echo "<td>$PosName</td>";
    echo "<td>" .$row['nhl_gp']. "</td>";
    echo "<td>" .$row['nhl_goals']. "</td>";
    echo "<td>" .$row['nhl_assists']. "</td>";
    echo "<td>$points</td>";
    echo "<td>" .$row['nhl_plus_minus']. "</td>";
    echo "<td>" .$row['nhl_ppg']. "</td>";
    echo "<td>" .$row['nhl_shg']. "</td>";
    echo "<td>" .$row['nhl_gwg']. "</td>";
    echo "<td>" .$row['nhl_hits']. "</td>";
    echo "<td>$p_mj</td>";
    echo "<td>" .$row['nhl_shots/saves']. "</td>";
    echo "<td>$p_t</td>";
    echo "<td>" .$row['nhl_pim']. "</td></tr>";
    }
    else
    {
     $ga = "" .$row['nhl_ga']. "";
          $saves = "" .$row['nhl_shots/saves']. "";
          $savep = $saves / ($ga + $saves);
          $savep = round($savep,3);
    $mbc = $ga / $row['nhl_gp'];
    $mbc = round($mbc,2);
    $pts = $row['nhl_assists'] + $row['nhl_goals'];
    echo "<tr $class><td>" .$row['player_name']. "</td>";
    echo "<td><img src='../images/logos/$team.png' width='40' height='20'/></td>";
    echo "<td>$PosName</td>";
    echo "<td>" .$row['nhl_gp']. "</td>";
    echo "<td>" .$row['nhl_wins']. "</td>";
    echo "<td>" .$row['nhl_loss']. "</td>";
    echo "<td>" .$row['nhl_otl']. "</td>";
    echo "<td>" .$row['nhl_ga']. "</td>";
    echo "<td>$mbc</td>";
    echo "<td>" .$row['nhl_shots/saves']. "</td>";
    echo "<td>$savep</td>";
    echo "<td>" .$row['nhl_shutouts']. "</td>";
    echo "<td>" .$row['nhl_goals']. "</td>";
    echo "<td>" .$row['nhl_assists']. "</td>";
    echo "<td>$pts</td></tr>";
    }
     }
     echo "</table>";
    ?>
       </div>
      </div>

    The players stats works fine.

    But when I switch to the goalers one:
    It bugs. It shows the table all right. But it ends right at this line:
    Code:
    echo "<td>$pts</td></tr>";
    And doesnt show anything else after

    I tried placing the
    </table>
    in the while loop, and it works... It stops displaying only after the 2nd closing bracket.

    Thanks for your help,

  2. #2
    jont87 is offline x10Hosting Member jont87 is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    17

    Re: Mysql and PHP help

    Taken a quick look and can''t find any issues but you could simplify your code in places. One in particular you could swap all the if else's for a switch command for example
    Code:
    switch($orderg)
    {
        case 'goals':
        break;
    
      case 'points':
      break;
    
      case 'wins':
      break;
    
      default:
    }

+ Reply to Thread

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  3. Process PHP from a MySQL array
    By tnl2k7 in forum Programming Help
    Replies: 12
    Last Post: 05-05-2008, 10:02 AM
  4. Creating MySql database/table using php script
    By bushimports in forum Free Hosting
    Replies: 1
    Last Post: 02-02-2008, 12:43 AM

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