Jump to content

League Table


benji87

Recommended Posts

Hey all im currently working on a league table for a rugby club. It all works fine apart from one bit i cant work out. What i need to do is work out the trys scored difference. So the number between what they have scored and what they have conceeded.

 

Now ive never been good at maths and im guessing there is just a simple formula for it to work but i just cant work it out! The user inputs the score of the game for each team with the score for and against for that team this is what i came up with to input into the database using the update function.

 

difference = difference + scored - against

 

This works correctly the first time but the second time you do it, it just adds the next difference onto the previous which is obviously wrong coz i want it to show the try difference from all games  :-\

 

Anybody have an answer?

Cheers

Link to comment
Share on other sites

So you want to do this for all games? BTW Rugby is a great sport, wish they had a club around my area.

 

<?php
// If your math is right above it would be like this to make sure it is properly done
$difference = $difference + ($scored - $against);
?>

 

That should work. The parenthesis can be critical sometimes. Give it a try and let me know.

Link to comment
Share on other sites

Yer thats right i want it to be worked out for all games. It didnt work  :-[ there is a problem with the syntax around ($scored - $aganist) any ideas??

 

Here is my query:

 

<?php
$sql = mysql_query("UPDATE ssrfc_league SET points = points + '$points', $result = '$result' + 1, played = played + 1, scored = scored + '$scored', against = against + '$against', difference = $difference + ($scored - $against) WHERE team='$team'") or die (mysql_error());
?>

 

Cheers

Link to comment
Share on other sites

<?php
$sql = mysql_query("UPDATE ssrfc_league SET points = points + '$points', $result = '$result' + 1, played = played + 1, scored = scored + '$scored', against = against + '$against', difference = ".($difference + ($scored - $against))." WHERE team='$team'") or die (mysql_error());
?>

 

Try that

Link to comment
Share on other sites

Whats the error you are getting?

 

$sql = mysql_query("UPDATE ssrfc_league SET points = (points + $points), result = ($result + 1), played = (played + 1), scored = (scored + $scored), against = (against + $against), difference = (difference + ".($scored - $against).") WHERE team='$team'") or die (mysql_error());

 

Maybe that will work?

Link to comment
Share on other sites

I would try:

 

<?php
$sql = mysql_query("UPDATE ssrfc_league SET points = points + '$points', $result = '$result' + 1, played = played + 1, scored = scored + '$scored', against = against + '$against', difference = '$difference' + ('$scored' - '$against') WHERE team='$team'") or die (mysql_error());
?>

 

(single quotes around $difference, $scored and $against)

Link to comment
Share on other sites

Works the same as my original code it just adds the result to the previous one contained in the database so basicly its just adding up the differences and not working out the difference between the two total numbers of scored and against.

 

Maybe i am going about this the wrong way??

Link to comment
Share on other sites

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.