phpbeginner Posted September 25, 2006 Share Posted September 25, 2006 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] Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted September 25, 2006 Author Share Posted September 25, 2006 Is this way off ? Quote Link to comment Share on other sites More sharing options...
craygo Posted September 25, 2006 Share Posted September 25, 2006 What does your table structure look like??Ray Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted September 25, 2006 Author Share Posted September 25, 2006 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) Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted September 25, 2006 Author Share Posted September 25, 2006 Any thoughts on this ? Quote Link to comment Share on other sites More sharing options...
craygo Posted September 25, 2006 Share Posted September 25, 2006 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: ".$wins." Wins - ".$losses." Losses Points: ".$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 Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted September 25, 2006 Author Share Posted September 25, 2006 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 Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted September 25, 2006 Author Share Posted September 25, 2006 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. Quote Link to comment Share on other sites More sharing options...
craygo Posted September 26, 2006 Share Posted September 26, 2006 OK so to get this rightteam1 plays team 2if team 2 wins they get one pointif teams 2 wins in ot they get one point for the win and one point for ot winjust want to get the scenerio correct. Also list any other senerio's so we can add it in.Ray Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted October 16, 2006 Author Share Posted October 16, 2006 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.