Jump to content


Photo

Hockey Standings Error


  • Please log in to reply
9 replies to this topic

#1 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 25 September 2006 - 03:06 PM

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 !

<?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");
  }
 
?>


#2 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 25 September 2006 - 03:44 PM

Is this way off ?

#3 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 25 September 2006 - 03:49 PM

What does your table structure look like??

Ray

#4 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 25 September 2006 - 03:52 PM

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)

#5 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 25 September 2006 - 04:45 PM

Any thoughts on this ?

#6 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 25 September 2006 - 04:51 PM

Try this

<?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>";
?>

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

#7 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 25 September 2006 - 04:55 PM

Yeah, I had just about figured it out. I will also try out yours. The only problem I had with mine was, it can't differentiate between teams so on an OT Game it gives 2 points for the win but also 1 Point for a loss and adds 1 to OTL

#8 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 25 September 2006 - 08:52 PM

Thank you, I used your code and it works flawlessly. The only thing I can't get to work and I have been trying is to check to see if the game is ot_game from my table. If it is and team 0002 loses then I need to add 1 point.

#9 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 26 September 2006 - 12:44 PM

OK so to get this right

team1 plays team 2

if team 2 wins they get one point
if teams 2 wins in ot they get one point for the win and one point for ot win

just want to get the scenerio correct. Also list any other senerio's so we can add it in.

Ray

#10 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 16 October 2006 - 12:07 AM

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
if(is_numeric($t1_score) && is_numeric($t2_score))
after this
while($r=mysql_fetch_array($res))
but that didn't work either.....Here is the 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>";
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users