how to use temporary values
-
Hi i have a mysql database which i use to update a soccer league table when i enter in results from a form, works fine, however i would like to be able to enter latest scores and update table based on latest scores entered but i cant work out how to do this as at the moment when i enter an update in the score for a match it will treat it as a new match and allocate points etc all over again Example teama 1 teamb 0 would give the following teama goals for 1, teamb goals for 0, goaldifference = teama goals for - teamb goals for which in thiscase would be 1 if it changed to teama 3 teamb 0 would give the following teama goals for 3, teamb goals for 0, goaldifference = teama goals for - teamb goals for which in thiscase would be 3 but it adds the 3 from this update to the 1 from previous update giving 4. so i need a way to stop it treating each update as a new result and only update with new data - the previous data so in my example 3 goals - 1 goal from first update = 2 goals , i have other fields like points that need to be treated same way. hope someone can helpout with this and point me in right direction kenny
-
Hi i have a mysql database which i use to update a soccer league table when i enter in results from a form, works fine, however i would like to be able to enter latest scores and update table based on latest scores entered but i cant work out how to do this as at the moment when i enter an update in the score for a match it will treat it as a new match and allocate points etc all over again Example teama 1 teamb 0 would give the following teama goals for 1, teamb goals for 0, goaldifference = teama goals for - teamb goals for which in thiscase would be 1 if it changed to teama 3 teamb 0 would give the following teama goals for 3, teamb goals for 0, goaldifference = teama goals for - teamb goals for which in thiscase would be 3 but it adds the 3 from this update to the 1 from previous update giving 4. so i need a way to stop it treating each update as a new result and only update with new data - the previous data so in my example 3 goals - 1 goal from first update = 2 goals , i have other fields like points that need to be treated same way. hope someone can helpout with this and point me in right direction kenny
Okay, how are you storing the data in the table (which I'll call Results). I'm imagining something like this after the first result:
RowId Team1Id Team2Id Team1Score Team2Score
0 1 2 1 0It sounds like you are doing an INSERT when you submit the data, which will give you:
RowId Team1Id Team2Id Team1Score Team2Score
0 1 2 1 0
1 1 2 3 0When you want to update the score, use an UPDATE command instead of a INSERT command. You'll need the row's Primary Key (RowId in my example), and you'll end up with this:
RowId Team1Id Team2Id Team1Score Team2Score
0 1 2 3 0As you want.