Jump to content

Hockey Standings Error


phpbeginner

Recommended Posts

I thought I had this problem corrected awhile ago ( with the fine help of members in here ) but I have one problem with the script below.
What I have is a hockey database in which I am trying to pull 1 team record from. This team can either be listed as Team 1 or Team 2 depending on wether it is a home or away game. The problem I am having is it this code below is just retrieving info from the team 1 side and creating the record. The scores are all entered correctly into my DB but rather than displaying a record of 13 Wins 11 Losses 26 Points, it is displaying 9 Wins 15 Losses 18 Points. Any Ideas ? Thanks In Advance !

[sub]<?php
$sql_standings = "SELECT * FROM schedule_scores WHERE 
      (team1 = '0002' OR team2 = '0002') AND
      season = '000000000001'";

  $result_standings = mysql_query("$sql_standings");
  $total_standings = mysql_numrows($result_standings);

  $standings_array = "";
  $standings_array = array();

  $i = 0;
  while ($i < $total_standings) {
      $team1 = mysql_result($result_standings,$i,"team1");
      $team2 = mysql_result($result_standings,$i,"team2");
      $t1_score = mysql_result($result_standings,$i,"team1_score");
      $t2_score = mysql_result($result_standings,$i,"team2_score");
      $gm_ot = mysql_result($result_standings,$i,"ot_game");
      $team1_id = 0002;
      $team2_id = 0002;

  if($tid == 0002)
  {
      if($t1_score > $t2_score)
      {
         
        $standings_array["w"] = $standings_array["w"] + 1;
        $standings_array["pts"] = $standings_array["pts"] + 2;
        $standings_array["l"] = $standings_array["l"] + 0;
        }
{
        if($t1_score > $t2_score AND $gm_ot == 1) {
            $standings_array["pts"] = $standings_array["pts"] + 1;
            $standings_array["otl"] = $standings_array["otl"] + 1;         
            $standings_array["l"] = $standings_array["l"] + 0;
         
        }
else if($t1_score < $t2_score)
            $standings_array["l"] = $standings_array["l"] + 1;
       
      }
  } else
{

      if($t2_score > $t1_score)
      {
         
        $standings_array["w"] = $standings_array["w"] + 1;
        $standings_array["pts"] = $standings_array["pts"] + 2;
        $standings_array["l"] = $standings_array["l"] + 0;
          }
  {
        if($t1_score < $t2_score AND $gm_ot == 1) {
            $standings_array["pts"] = $standings_array["pts"] + 1;
            $standings_array["otl"] = $standings_array["otl"] + 1;
            $standings_array["l"] = $standings_array["l"] + 0;
  }
  else if($t2_score < $t1_score)
            $standings_array["l"] = $standings_array["l"] + 1;     
           
         
     
      }
  }
  $i++;
}$testteam_array = array();  {
        echo  $standings .= "
                <tr bgcolor=\"#FFFFFF\" align=\"left\" valign=\"middle\">
                                                  <td class=\"table_text\" align=center>".$standings_array["w"]."</td>
                  <td class=\"table_text\" align=center>".$standings_array["l"]."</td><td class=\"table_text\" align=center>".$standings_array["otl"]."</td>
                                                        <td class=\"table_text\" bgcolor=\"#efefef\" align=center>".$standings_array["pts"]."</td></tr>";

      //ADD TEAMS WITH STANDINGS TO TESTTEAM ARRAY
        $t_w_stats = $value["id"];
              array_push($testteam_array, "$t_w_stats");
  }
 
?>[/sub]
Link to comment
https://forums.phpfreaks.com/topic/21990-hockey-standings-error/
Share on other sites

id int  unsigned zerofill NOT NULL auto_increment,
   date date DEFAULT '0000-00-00' NOT NULL,
   time varchar(10) NOT NULL,
   location varchar(50) NOT NULL,
   team1 varchar(50) NOT NULL,
   team2 varchar(50) NOT NULL,
   team1_div int(4) unsigned zerofill DEFAULT '0000' NOT NULL,
   team2_div int(4) unsigned zerofill DEFAULT '0000' NOT NULL,
   team1_score varchar(5) DEFAULT '0' NOT NULL,
   team2_score varchar(5) DEFAULT '0' NOT NULL,
   season int(12) unsigned zerofill DEFAULT '000000000000' NOT NULL,
   summary longtext NOT NULL,
   ot_game tinyint(1) DEFAULT '0' NOT NULL,
   PRIMARY KEY (id)
Link to comment
https://forums.phpfreaks.com/topic/21990-hockey-standings-error/#findComment-98281
Share on other sites

Try this

[code]<?php
$wins = 0;
$losses = 0;
$sql_standings = "SELECT * FROM schedule_scores WHERE
      (team1 = '0002' OR team2 = '0002') AND
      season = '000000000001'";
   $res = mysql_query($sql_standings) or die (mysql_error());
     while($r=mysql_fetch_array($res)){
        if($r['team1'] == '0002'){
          $result = $r['team1_score'] - $r['team2_score'];
            if($result < 0){
              $win = 0;
              $lose = 1;
              } else {
              $win = 1;
              $lose = 0;
              }
        }
        if($r['team2'] == '0002'){
          $result = $r['team2_score'] - $r['team1_score'];
            if($result < 0){
              $win = 0;
              $lose = 1;
            } else {
              $win = 1;
              $lose = 0;
            }
        }
$wins += $win;
$losses += $lose;
     }
$points = $wins * 2;
echo "Team 2:&nbsp;&nbsp;&nbsp;&nbsp;".$wins." Wins - ".$losses." Losses &nbsp;&nbsp;&nbsp;&nbsp;Points:&nbsp;&nbsp;".$points."<br>";
?>[/code]

If you have certain points for certain things let me know will help out with that.

Sorry I didn't mean to change your code around. this seemed a little simpler.


Ray
Link to comment
https://forums.phpfreaks.com/topic/21990-hockey-standings-error/#findComment-98335
Share on other sites

  • 3 weeks later...
Okay, this is just about working and maybe someone can help. The problem is that any game that has yet to be played is being added into as a game played and a win ( 40 games in schedule and none have been played but shows 40 GP and 40 wins with 80 Points ) . I tried changing the statement, to get results only if team1_score and team2_score are NOT NULL but no luck. I also tried adding this [code]if(is_numeric($t1_score) && is_numeric($t2_score))[/code] after this [code]while($r=mysql_fetch_array($res))[/code] but that didn't work either.....Here is the code.

[code]<?php
$wins = '-';
$losses = '-';
$gp = '-';
$otlosses = '-';
$sql_standings = "SELECT * FROM schedule_scores WHERE
      (team1 = '0002' OR team2 = '0002') AND
      season = '000000000002'";
  $res = mysql_query($sql_standings) or die (mysql_error());
    while($r=mysql_fetch_array($res))
      { 
          $result = $r['team1_score'] - $r['team2_score'];
            if($result < 0){
                  if($r[ot_game] == 1) {
                      $otl = 1;
                      $lose = 0;
                      $win = 0;
                    } else {
                      $lose = 1;
                      $otl = 0;
                      $win = 0;
                    }
              } else {
              $win = 1;
              $otl = 0;
              $lose = 0;
              }
        }
        if($r['team2'] == '0002'){
          $result = $r['team2_score'] - $r['team1_score'];
            if($result < 0){
                  if($r[ot_game] == 1) {
                      $otl = 1;
                      $lose = 0;
                      $win = 0;
                    } else {
                      $lose = 1;
                      $otl = 0;
                      $win = 0;
                    }
              } else {
              $win = 1;
              $otl = 0;
              $lose = 0;
              }
        }
$wins += $win;
$losses += $lose;
$otlosses += $otl;
$gp = ROUND($wins + $losses + $otlosses);
    }
$points = ($wins * 2) + $otlosses;
echo "<tr bgcolor=\"#FFFFFF\" align=\"left\" valign=\"middle\">
                                                  <td class=\"table_text\" bgcolor=\"#EFEFEF\" align=center>".$gp."</td> <td class=\"table_text\" bgcolor=\"#BEBEBE\"align=center>".$wins." </td> <td class=\"table_text\" bgcolor=\"#EFEFEF\" align=center>".$losses."</td>
<td class=\"table_text\" bgcolor=\"#BEBEBE\" align=center>".$otlosses."</td>
                                                        <td class=\"table_text\" bgcolor=\"#EFEFEF\" align=center>".$points."</td></tr>";
?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.