Solarpitch Posted November 21, 2008 Share Posted November 21, 2008 Hi Guys, I need a little help with this code please. It's for a golf application and I'm trying to calculate the amount of Pars, Birdies, Bogeys etc for each hole 1 - 18 that the player has had this year. Example.. Round Played: 3 Hole Pars Birdies Bogeys etc..... 1 2 1 0 2 1 0 2 3 3 0 0 and so on. I almost have it working. I have the code to query the database, and calculate the results being Par, Birdies etc etc. Here's what I'm working on.. <?php function hole_breakdown($id, $year) { dbconnect(); $query = "SELECT * FROM golf_scoredata where ID = '".$id."' and year = '".$year."'"; $result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR); $my_info[0] = "<table cellspacing='2' cellpadding='0'> <tr> <td>Hole</td> <td>Index</td> <td>Pars</td> <td>Birdies</td> <td>Bogeys</td> <td>Doubles</td> <td>Triples</td> <td>Quads</td> <td>Eagles</td> <td>Albatros</td> <td>No Result</td> </tr>"; while(($row = mysql_fetch_array($result)) != false) { // Loop 18 times for each hole 1 - 18 to calculate scores for ($i=1; $i<19; $i++ ) { $hole = $i; $par = $row["hole".$i."par"]; $p = $par1; //Par $b = $par1 + 1; //Bogey $db = $par1 + 2; //Double Bogey //and so on... //Get the user's score for the hole $score1 = $row["hole".$i."score"]; if ($score1 == $p ){$total_par++;} if ($score1 == $b ){$total_bogey++;} if ($score1 == $db ){$total_doubles++;} //Calculate the score for each holes. So how many Pars on Hole 1, How many on Hole 2 and so on... if (($score1 == $p) && ($i == $i)){$pars.$i++;} if (($score1 == $bo) && ($i == $i)){$bogeys.$i++;} if (($score1 == $p) && ($i == $i)){$pars.$i++;} if (($score1 == $bo) && ($i == $i)){$bogeys.$i++;} } } ?> This is as far as I got. Any help would be great Link to comment https://forums.phpfreaks.com/topic/133635-help-needed-with-calculating-scores/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.