Jump to content

Recommended Posts

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.. ......

[sup]<?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>"

?>[/sup]
Link to comment
https://forums.phpfreaks.com/topic/20390-hockey-stats-help/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/20390-hockey-stats-help/#findComment-89863
Share on other sites

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)
Link to comment
https://forums.phpfreaks.com/topic/20390-hockey-stats-help/#findComment-89870
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/20390-hockey-stats-help/#findComment-89888
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/20390-hockey-stats-help/#findComment-89890
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.