After thinking and messing around with the code more, I’m trying to make a handicap calculator…
these are the requirements for a accurate calculation
As we see in the above example, this golfer with a handicap of 12.7, has also turned in a score of 97. Thus, when he has a bad round of 95 or higher, people are likely to sneer and say, “Are you sure your are a 12 handicap?”
This is because people, in general, do not really understand the golf handicap system. Your golf handicap represents your best rounds of golf not your average rounds of golf.
As you play more golf, you factor in more scores. With five rounds of golf, only the one score is factored. With seven rounds of golf, you average your two lowest differential numbers, and then multiply by .96.
Finally, once you have played 20 rounds of golf, you take the average of your 10 lowest differentials and multiply that number by .96. Obviously then, the more golf you play, the more accurate your handicap becomes.
When a user submits a round the validation.php page does most of the calculation. This is my validation page
$selectedcourse = $_POST['course'];
//if the name exists it gives an error
$result = mysql_query("SELECT * FROM courses WHERE courseName = '$selectedcourse'");
while ($row=mysql_fetch_array($result)) {
$par = $row['par'];
$rating = $row['courseRating'];
$slope = $row['slopeRating'];
$difference = $_POST['score'] - $par;
$coursescore = $_POST['score'] - $rating;
$coursemultiply = $coursescore * 113;
$differental = $coursemultiply / $slope;
$handicap = $differental * .96;
// now we insert it into the database
$insert = "INSERT INTO rounds (username, dateplayed, courseplayed, par, score, difference, differental, handicap, coursecondition, weather, wind)
VALUES ('".$_SESSION['username']."', '".$_POST['dateplayed']."', '".$_POST['course']."', '".$row['par']."', '".$_POST['score']."', '".$difference."', '".$differental."', '".$handicap."', '".$_POST['condition']."', '".$_POST['weather']."', '".$_POST['wind']."')";
$add_member = mysql_query($insert);
So in the “rounds” table the differential and the handicap is already present and correct. On the main profile for the member I want to show their current handicap using the above guidelines. I have been trying to do this like so
$result = mysql_query("SELECT * FROM rounds where username ='$user'");
$num_rows = mysql_num_rows($result);
if ($num_rows >= 1)
echo "You have $num_rows round in the system.";
else
echo "You have $num_rows rounds in the system.";
echo "<br />";
$result = mysql_query("SELECT * FROM rounds WHERE username = '$user' ORDER BY differental ASC");
while ($row=mysql_fetch_array($result))
$num_rows = mysql_num_rows($result);
if ($num_rows == 0) { echo"";}
elseif ($num_rows == 1){
$handicap = $row['differental'] * 0.96;
echo "Current Handicap: ",$handicap,"";}
elseif ($num_rows == 2) echo"test";
The above code should work if only one round is in the table but the result of the if statement is
You have 1 round in the system.
Current Handicap: 0
Im pretty sure the above code will never work since I have no way to get the average differential. I think I need to use a function and I dont have a lot of experience with function and am not sure if I can add date from database in a function.