phpbeginner Posted September 11, 2006 Share Posted September 11, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/20390-hockey-stats-help/ Share on other sites More sharing options...
phpbeginner Posted September 11, 2006 Author Share Posted September 11, 2006 Am I way off on this ? Quote Link to comment https://forums.phpfreaks.com/topic/20390-hockey-stats-help/#findComment-89838 Share on other sites More sharing options...
ober Posted September 11, 2006 Share Posted September 11, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/20390-hockey-stats-help/#findComment-89863 Share on other sites More sharing options...
phpbeginner Posted September 11, 2006 Author Share Posted September 11, 2006 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) Quote Link to comment https://forums.phpfreaks.com/topic/20390-hockey-stats-help/#findComment-89870 Share on other sites More sharing options...
ober Posted September 11, 2006 Share Posted September 11, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/20390-hockey-stats-help/#findComment-89873 Share on other sites More sharing options...
phpbeginner Posted September 11, 2006 Author Share Posted September 11, 2006 ahhh, I see, thanks for that I appreciate it. What about point 1 ? Quote Link to comment https://forums.phpfreaks.com/topic/20390-hockey-stats-help/#findComment-89875 Share on other sites More sharing options...
ober Posted September 11, 2006 Share Posted September 11, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/20390-hockey-stats-help/#findComment-89888 Share on other sites More sharing options...
phpbeginner Posted September 11, 2006 Author Share Posted September 11, 2006 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-2TeamName GP-1 W-0 L-1 Pts-0When I am looking for Team GP-4 W-1 L-3 Pts-2I hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/20390-hockey-stats-help/#findComment-89890 Share on other sites More sharing options...
phpbeginner Posted September 11, 2006 Author Share Posted September 11, 2006 Okay Thanks for the time and help.....I finally got it Quote Link to comment https://forums.phpfreaks.com/topic/20390-hockey-stats-help/#findComment-89899 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.