April 6, 201214 yr Looking for some help if anyone can do spare some time... I'm stuck with a query, and I have no idea on how to solve this, so I'm showing what I have in the hope that someone can help, and if not, then perhaps point me in the right direction... So I have a database with some results inside it, lets say it's football. Every week I add the new results, for the teams, and I'm echo'ing the results to a webpage. Simple enough so far.. I'm stuck with the problem of if Team A plays Team B, then the week later Team A plays Team C. In the first match they score 2 goals... so the record in the database is Team A 2 - Team B 0. Then in the next match they score 3 goals, so the next record is Team A 3 - Team C 1. I can get the results so they print each record on a line, with a loop. The issue I'm having, is I only want Team A = 5 goals <next line> team C = 1 goal <next line> team B = 0 goals.. So it lists every team, by the amount of goals they have, by combining all goals across each record related to the team, rather than printing every record. Code that I have so far.... <?php while($row = mysql_fetch_assoc($result)) { ?> <tr bgcolor="#FFFFFF" class="noborder"> <td><?php echo ($row['Team_Name']); ?></td> <td><?php echo $row['Team_Goals']; ?></td> </tr> <?php } ?> Can anyone help?
April 6, 201214 yr Looking for some help if anyone can do spare some time... I'm stuck with a query, and I have no idea on how to solve this, so I'm showing what I have in the hope that someone can help, and if not, then perhaps point me in the right direction... So I have a database with some results inside it, lets say it's football. Every week I add the new results, for the teams, and I'm echo'ing the results to a webpage. Simple enough so far.. I'm stuck with the problem of if Team A plays Team B, then the week later Team A plays Team C. In the first match they score 2 goals... so the record in the database is Team A 2 - Team B 0. Then in the next match they score 3 goals, so the next record is Team A 3 - Team C 1. I can get the results so they print each record on a line, with a loop. The issue I'm having, is I only want Team A = 5 goals <next line> team C = 1 goal <next line> team B = 0 goals.. So it lists every team, by the amount of goals they have, by combining all goals across each record related to the team, rather than printing every record. Code that I have so far.... <?php while($row = mysql_fetch_assoc($result)) { ?> <tr bgcolor="#FFFFFF" class="noborder"> <td><?php echo ($row['Team_Name']); ?></td> <td><?php echo $row['Team_Goals']; ?></td> </tr> <?php } ?> Can anyone help? Why don't you write a function from data you have already and filter what's needed?
Create an account or sign in to comment