Location: PHPKode > projects > GolfstatsPHP > golfstatsphp_3.0/updatecourseranks.php
<?
include("dbasecon.inc.php");
include("session.inc.php");
include ("header.php");
include ("statscoursefunctions.inc.php");

//get list of courses

$coursesql="select *,courseid as maincourseid from courses   

					order by courses.coursename desc";
				$coursequery=mysql_query($coursesql);
				$courserow=mysql_fetch_array($coursequery);
				$courseexist=mysql_numrows($coursequery);


//1.first delete everything (u can see why this only runs once a while!)

$deleteall="Delete from holerank";
$deleteallresult=mysql_query($deleteall);

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">



<? showheader("Course Manager"); ?>

<?

################Here we decide to internally calculate the HOLE STATS for each course!!!###########

do {

extract($courserow);
echo "<br>Processing for Course $maincourseid<br>";

echo "<br>========================<br>";



$hole=0;



do {

$hole=$hole+1;



$holesql="select courseid,gross,net,fairway_hit,gir,putt, sand_save  

					from hole$hole where courseid='$maincourseid'";

				$holequery=mysql_query($holesql);

				$holerow=mysql_fetch_array($holequery);

				$holeexist=mysql_numrows($holequery);

//this is pretty cool so we can dont count in the putts with na
$hole2sql="select courseid,gross,net,fairway_hit,gir,putt, sand_save  

					from hole$hole where courseid='$maincourseid' and putt<>'na'";

				$hole2query=mysql_query($hole2sql);

				$hole2row=mysql_fetch_array($hole2query);

				$hole2exist=mysql_numrows($hole2query);

echo $hole2sql;

if ($holeexist) {





//this is for the basic info of the hole

$lengthhole=lengthhole.$hole;

$indexhole=indexhole.$hole;

$parhole=parhole.$hole;



//global

$allgross=allgross.$hole;

$allnet=allnet.$hole;

$allnetscore=allnetscore.$hole;

$allgrossscore=allgrossscore.$hole;



$allroundsplay=allroundsplay.$hole;

$allroundsplay2=allroundsplay2.$hole;

$allavggross=allavggross.$hole;

$allavgnet=allavgnet.$hole;

$allavggrossscore=allavggrossscore.$hole;

$allavgnetscore=allavgnetscore.$hole;



$allfways=allfways.$hole;

$allgir=allgir.$hole;

$allputts=allputts.$hole;





${$allgross}=0;

${$allnet}=0;

${$allgrossscore}=0;

${$allnetscore}=0;

${$allavgnetscore}=0;

${$allavggrossscore}=0;





${$allputts}=0;

$allfwayspct=0;

$allgirpct=0;

${$allfways}=0;

${$allgir}=0;





//loop the hole

do { 

extract($holerow);

//do the counting for personal scores

//count rounds

${$allroundsplay}=$holeexist;

${$allroundsplay2}=$hole2exist;


//count allgross

${$allgross}=${$allgross}+$gross;

//count allnet

${$allnet}=${$allnet}+$net;



//count allgrossscore

${$allgrossscore}=($gross-${$parhole})+${$allgrossscore};

//count allnet

${$allnetscore}=($net-${$parhole})+${$allnetscore};



//count all fairways

${$allfways}=${$allfways}+$fairway_hit;

//countall girs

${$allgir}=${$allgir}+$gir;

//countall sandsave

${$allsandsave}=${$allsandsave}+$sand_save;


//countall putts

${$allputts}=${$allputts}+$putt;





} while ($holerow=mysql_fetch_array($holequery));



echo "<br>======================================<br>";

echo "Roundsthis hole$hole: ${$allroundsplay} "."<p>";

echo "Roundsthis hole$hole with NA: ${$allroundsplay2} "."<p>";


//count totals!

${$allavggross}= number_format((${$allgross}/${$allroundsplay}),2,'.','');

${$allavgnet}= number_format((${$allnet}/${$allroundsplay}),2,'.','');

${$allavggrossscore}= number_format((${$allgrossscore}/${$allroundsplay}),2,'.','');

${$allavgnetscore}= number_format((${$allnetscore}/${$allroundsplay}),2,'.','');



$allfwaypct= number_format((${$allfways}/(${$allroundsplay}))*100,2,'.','');

$allgirpct= number_format((${$allgir}/${$allroundsplay})*100,2,'.','');

${$allavgputt}=number_format((${$allputts}/${$allroundsplay2}),2,'.','');





echo "<p>For HOLE $hole in $maincourseid: 

Par ${$parhole}Average Net:${$allavgnet} Avg Gross:${$allavggross} Fway Hits: $allfwaypct, GIR: $allgirpct, Avg Putts:

${$allavgputt} length:${$lengthhole} grossscore:${$allavggrossscore} netscore:${$allavgnetscore}<p>";





//OK, ready to put inside holeranks!







//2.Now slowly put in all things



 $holeaddsql = "INSERT INTO holerank (courseid, holeid, par, avggross, avgnet, fwayhitpct, girpct, avgputt, holelength

 ,avgscoregross,avgscorenet) 

 VALUES ('$maincourseid', '$hole', '${$parhole}', '${$allavggross}', '${$allavgnet}', '$allfwaypct', '$allgirpct', 

 '${$allavgputt}', '${$lengthhole}', '${$allavggrossscore}', '${$allavgnetscore}')";



			$holeaddresult=mysql_query($holeaddsql);





}//endif holeexist



} while ($hole<18);


} while ($courserow=mysql_fetch_array($coursequery));

#################################################### 

?>



























<? showfooter(); ?>

Return current item: GolfstatsPHP