benji87 Posted March 21, 2007 Share Posted March 21, 2007 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 Quote Link to comment Share on other sites More sharing options...
per1os Posted March 21, 2007 Share Posted March 21, 2007 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. Quote Link to comment Share on other sites More sharing options...
benji87 Posted March 21, 2007 Author Share Posted March 21, 2007 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 Quote Link to comment Share on other sites More sharing options...
per1os Posted March 21, 2007 Share Posted March 21, 2007 <?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 Quote Link to comment Share on other sites More sharing options...
benji87 Posted March 21, 2007 Author Share Posted March 21, 2007 Nope it really dont like that.... Quote Link to comment Share on other sites More sharing options...
per1os Posted March 21, 2007 Share Posted March 21, 2007 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? Quote Link to comment Share on other sites More sharing options...
UTAlan Posted March 21, 2007 Share Posted March 21, 2007 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) Quote Link to comment Share on other sites More sharing options...
benji87 Posted March 22, 2007 Author Share Posted March 22, 2007 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?? 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.