lukep11a Posted July 17, 2012 Share Posted July 17, 2012 Hi, I am currently working on making my website more efficient and just trying to get some advice on the best way to do something. It's a fantasy football website. The tables I have are teams, fixtures, results and teamselections. I used to have a formula in excel to calculate the points after each team had played. Then I would import into the results table in its own column - points. I have since thought that it would be better to let php calculate the points scored for each game. So I have created a function that will succesfully do that. Great. So the next part would be to calculate each users total points, i.e the total sum of all the teams points that they have selected. Before when I had a dedicated points column in the results table I would simply SELECT SUM(points). But now I don't have a points column and instead have a function so am not sure how to do this or if I should go back to the way I used to do it. If anyone has any ideas I would be very much appreciated. Quote Link to comment Share on other sites More sharing options...
ignace Posted July 17, 2012 Share Posted July 17, 2012 We are going to need to see your tables and their columns to tell you the appropriate query. You shouldn't have to use a PHP function to count this for you. MySQL can tell you these easily. Quote Link to comment Share on other sites More sharing options...
lukep11a Posted July 17, 2012 Author Share Posted July 17, 2012 teams team_id team_name fixtures fixture_id home_team_id away_team_id date results fixture_id home_team_goals away_team_goals team_selections user_team_id team_id These are my 4 main tables. I can calculate how many points each teams get based on the number of goals they score and how many goals there opponent scored. I created this to calculate the points for the home team and away team. $ht_league_dif = $ht_league_id - $at_league_id; if ($ht_league_dif <= 0) { $ht_league_dif = 0; } $at_league_dif = $at_league_id - $ht_league_id; if ($at_league_dif <= 0) { $at_league_dif = 0; } if ($ht_goals > $at_goals) { $ht_result_points = 30; $at_result_points = 0; } elseif ($ht_goals == $at_goals) { $ht_result_points = 10; $at_result_points = 10; } elseif ($ht_goals < $at_goals) { $ht_result_points = 0; $at_result_points = 30; } $ht_goals_points = $ht_goals * 5; $at_goals_points = $at_goals * 5; if ($ht_goals == 0) { $at_cs_points = 5; } if ($at_goals == 0) { $ht_cs_points = 5; } $ht_points = ((1 + $ht_league_dif) * ($ht_goals_points + $ht_result_points + $ht_cs_points)); $at_points = ((1 + $at_league_dif) * ($at_goals_points + $at_result_points + $at_cs_points)); So that works fine to calculate the points scored for one game at a time. I just need to be able to calculate the total points for each team and then the total points for each user based on which teams they have selected. 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.