Jump to content


Photo

Hockey Stats Help


  • Please log in to reply
8 replies to this topic

#1 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 11 September 2006 - 02:00 PM

I am having problems displaying one team record from a DB. The website is for one team but keeps track of home away games. When its an away game the team is then put under team 2. What I am doing is getting the record from scores for the team which could either be under team 1 or team 2 from the DB but its showing up as 2 seperate teams rather than totalling to one team. Here is what I have.. ......

<?php
$sql_standings = "SELECT * FROM schedule_scores WHERE "
      ."(team1 = '0002' OR team2 = '0002') AND "
      ."season = '000000000009'";
  $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[$team1]["w"] = $standings_array[$team1]["w"] + 1;
        $standings_array[$team1]["pts"] = $standings_array[$team1]["pts"] + 2;
        $standings_array[$team1]["l"] = $standings_array[$team1]["l"] + 0;
      }elseif($t1_score < $t2_score){
        if($gm_ot == 1) {
            $standings_array[$team1]["otl"] = $standings_array[$team1]["otl"] + 1;
            $standings_array[$team1]["pts"] = $standings_array[$team1]["pts"] + 1;
            $standings_array[$team1]["l"] = $standings_array[$team1]["l"] + 0;
        }else{
            $standings_array[$team1]["l"] = $standings_array[$team1]["l"] + 1;
        }
      }
  } else {
      if($t2_score > $t1_score)
      {
        $standings_array[$team1]["w"] = $standings_array[$team1]["w"] + 1;
        $standings_array[$team1]["pts"] = $standings_array[$team1]["pts"] + 2;
        $standings_array[$team1]["l"] = $standings_array[$team1]["l"] + 0;
              }elseif($t2_score < $t1_score){
        if($gm_ot == 1) {
            $standings_array[$team1]["otl"] = $standings_array[$team1]["otl"] + 1;
            $standings_array[$team1]["pts"] = $standings_array[$team1]["pts"] + 1;
            $standings_array[$team1]["l"] = $standings_array[$team1]["l"] + 0;
        }else{
            $standings_array[$team1]["l"] = $standings_array[$team1]["l"] + 1;
        }
      }
  }
  $i++;
}
$testteam_array = array();
while (list ($key, $value) = each ($standings_array)) {
      $standings .=
              print "<tr bgcolor=\"#FFFFFF\" align=\"left\" valign=\"middle\">
                <td class=\"table_text\" align=center>".$value["gp"]."</td>
                <td class=\"table_text\" align=center>".$value["w"]."</td>
                <td class=\"table_text\" align=center>".$value["l"]."</td>
                <td class=\"table_text\" align=center>".$value["d"]."</td>
                <td class=\"table_text\" align=center>".$value["otl"]."</td>
                <td class=\"table_text\" bgcolor=\"#efefef\" align=center>".$value["pts"]."</td>
                <td class=\"table_text\" align=center>".$value["gf"]."</td>
                <td class=\"table_text\" align=center>".$value["ga"]."</td>";

//ADD TEAMS WITH STANDINGS TO TESTTEAM ARRAY
$t_w_stats = $value["id"];
        array_push($testteam_array, "$t_w_stats");
}
print "  </td>
  </tr>
</table>"

?>


#2 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 11 September 2006 - 02:57 PM

Am I way off on this ?

#3 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 11 September 2006 - 03:47 PM

Ok a few things:

1) I don't totally understand what is going wrong.  Can you describe it better?
2) Your 2 giant if/else blocks... those are identical.  I think you can minimize some of that code quite a bit.
3)    $standings .=
                print "<tr bgcolor=\"#FFFFFF\" align=\"left\" valign=\"middle\">
                  <td class=\"table_text\" align=center>".$value["gp"]."</td>
                  <td class=\"table_text\" align=center>".$value["w"]."</td>

You don't "print" stuff to a variable.  You just set the variable equal to the text.

Info: PHP Manual


#4 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 11 September 2006 - 04:02 PM

1) In my table where I am getting this data, there is a team 1 score and then there is a team 2 score depending on home or away games were played. This code generates the output as if team id 0002 was 2 seperate teams. It comes out as Team 1 is 0 wins 3 losses, etc. then displays underneath Team 2 is 1 win 0 losses, when team 1 and team 2 are actually the same team. I am trying to combine into 1 stat.

2)The giant id/else blocks are different in the sense that the first is if($t1_score > $t2_score) and the second is  if($t2_score > $t1_score)

#5 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 11 September 2006 - 04:22 PM

2) Right... but it's the same code.  You could put that into a function.  Repeating giant chunks of code like that is inefficient.  If you have to change something in one, you have to change it in the other.  What's the point in that?

Info: PHP Manual


#6 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 11 September 2006 - 04:29 PM

ahhh, I see, thanks for that I appreciate it. What about point 1 ?

#7 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 11 September 2006 - 04:51 PM

Well, there's a few things I see.  You're depending on PHP to do much of the work when you could use SUM and other things in various queries to get some of the stats you're looking for.

I guess I'm not clear on what you're having a problem with.  Is it a math problem?  Is it a looping problem?  It's hard without seeing the output and what it is doing incorrectly.

Also, you're wasting processor time at the top: $sql_standings = "SELECT * FROM schedule_scores WHERE "
      ."(team1 = '0002' OR team2 = '0002') AND "
      ."season = '000000000009'";

That's 2 unnecessary concatentations.  Unless there is a flaw in your editor that you're trying to get around, you can just continue the string as-is.
$sql_standings = "SELECT * FROM schedule_scores WHERE 
      (team1 = '0002' OR team2 = '0002') AND
      season = '000000000009'";

Concatenations are processor expensive and the less you have to do them, the better.

Info: PHP Manual


#8 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 11 September 2006 - 04:57 PM

cool. thanks for that tip also. Its not a math problem, my output is fine other than its displaying 2 seperate outputs. Its tracking everything fine and w, l, pts are all correct its just doing this as an example:

TeamName GP-3 W-1 L-2 Pts-2
TeamName GP-1 W-0 L-1 Pts-0

When I am looking for
Team GP-4 W-1 L-3 Pts-2

I hope that helps.

#9 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 11 September 2006 - 05:20 PM

Okay Thanks for the time and help.....I finally got it






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users