Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/265842-sum-of-values-stored-in-a-function/
Share on other sites

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.

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.