Location: PHPKode > projects > GolfstatsPHP > golfstatsphp_3.0/statscourse2.php
<?

include("dbasecon.inc.php");

include("session.inc.php");

include ("header.php");

include ("statscoursefunctions.inc.php");





if ($HTTP_GET_VARS['courseid']) {



//first check see if course already exist



$coursechecksql="select * from courses where courseid='$courseid'";

				$coursecheckquery=mysql_query($coursechecksql);

				$coursecheckrow=mysql_fetch_array($coursecheckquery);

				$coursecheckexist=mysql_numrows($coursecheckquery);

				



if ($coursecheckexist) {				









?>



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



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



<? echo "<p class='error'>".$error."<p>"; ?>





<p>



<?

extract($coursecheckrow);



//we gotta break up the location to a more meaningful size and the notes as well

$courseloc=explode(",",$courseaddress);

$addresscount=count($courseloc);



$coursenotes1=explode(".",$coursenotes);

$notescount=count($coursenotes1);



?>

<table width="100%" border=0>

<tr><td>



<table border=1 width=100%>

<tr>

<td class="menu-bg">Course ID</td><td><? echo $courseid ?></td></tr><tr>

<td class="menu-bg">Name</td><td><? echo $coursename ?></td></tr><tr>

<td class="menu-bg">Location</td><td>

<? 

for ($i = 0; $i <= $addresscount; $i++) {

  echo "$courseloc[$i] <br>";

}	 

?>

</td></tr><tr>

<td class="menu-bg">State</td><td><? echo $coursestate ?></td></tr><tr>

<td class="menu-bg">Phone</td><td><? echo $coursephone ?></td></tr><tr>

<td class="menu-bg">Fax</td><td><? echo $coursefax ?></td></tr><tr>

<td class="menu-bg">Web Site</td><td><? echo $courseweb ?></td></tr><tr>

<td class="menu-bg">Course Rating</td><td><? echo $courserating ?></td></tr><tr>

<td class="menu-bg">Slope Rating</td><td><? echo $sloperating ?></td></tr>



</table>



</td>

<td>

<table border=1 width=100%>

<tr>

<td class="menu-bg">Notes</td><td>

 

<? 

for ($i = 0; $i <= $notescount; $i++) {

  echo "$coursenotes1[$i] <br>";

}	 

?></td></tr><tr>

</tr>

</table>



</td>

</tr>

</table>

<?













?>

<p>

<b>Click on hole # to view analysis.</b>

</p>

<table border=1>

<tr class="menu-bg">

<td>Hole</td><td><? echo $measure; ?></td><td>Index</td><td>Par</td><td>Your.Gross</td><td>Avg.Gross</td><td>Your.Net</td>

<td>Avg.Net</td><td>Fway Hit</td><td>GIR</td><td>Sand.Save</td><td>Avg.Putt</td><td>Rank</td>





</tr>







<?



###alrite, before antything else, lets get the ranking for this hole





$ranksql="select *  

					from holerank 		 								  

					where courseid='$courseid'

					order by avgscorenet DESC, avgscoregross DESC, avgnet DESC , avggross DESC, avgputt DESC, 

					girpct ASC, fwayhitpct ASC, sandsavepct ASC";				

 

				$rankquery=mysql_query($ranksql);

				$rankrow=mysql_fetch_array($rankquery);

				$rankexist=mysql_numrows($rankquery);

$rankstatus=0;

//what if no stats??

if ($rankexist) {

do {

$rankstatus++;

$holeid=$rankrow['holeid'];

${rank.$holeid}=$rankstatus;

} while ($rankrow=mysql_fetch_array($rankquery));

				





$hole=0;



do {



$hole=$hole+1;

















$holesql="select *  

					from hole$hole 		 								  

					where courseid='$courseid'";

				$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='$courseid' and putt<>'na'";

				$hole2query=mysql_query($hole2sql);

				$hole2row=mysql_fetch_array($hole2query);

				$hole2exist=mysql_numrows($hole2query);

if ($hole2exist) {
$allroundsplay2=$hole2exist;
} else {
$allroundsplay2=1;
}

if ($holeexist) {





//this is for the basic info of the hole

$lengthhole=lengthhole.$hole;

$indexhole=indexhole.$hole;

$parhole=parhole.$hole;

$rankhole=rank.$hole;

//global

$allgross=allgross.$hole;

$allnet=allnet.$hole;

$allroundsplay=allroundsplay.$hole;

//$allroundsplay2=allroundsplay2.$hole;

$allavggross=allavggross.$hole;

$allavgnet=allavgnet.$hole;





$allfways=allfways.$hole;

$allgir=allgir.$hole;

$allsandsave=allsandsave.$hole;

$allputts=allputts.$hole;





//personal

$mygross=mygross.$hole;

$mynet=mynet.$hole;

$roundsplay=roundsplay.$hole;

$myavggross=myavggross.$hole;

$myavgnet=myavgnet.$hole;



$myputts=myputts.$hole;

$myfways=myfways.$hole;

$mygir=mygir.$hole;

$mysandsave=mysandsave.$hole;





do {

extract($holerow);

//do the counting for personal scores

if ($userid == $login_id) {

//count rounds

${$roundsplay}=${$roundsplay}+1;

//count mygross

${$mygross}=${$mygross}+$gross;

//count mynet

${$mynet}=${$mynet}+$net;

//count my fairways

${$myfways}=${$myfways}+$fairway_hit;

//count my gir

${$mygir}=${$mygir}+$gir;

${$mysandsave}=${$mysandsave}+$sandsave;

//count my putts

${$myputts}=${$myputts}+$putt;



}//endif





//count rounds

${$allroundsplay}=${$allroundsplay}+1;


//count allgross

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

//count allnet

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

//count all fairways

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

//countall girs

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

${$allsandsave}=${$allsandsave}+$sandsave;

//countall putts

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







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



//count totals!

if (${$roundsplay}) {

${$myavggross}= number_format((${$mygross}/${$roundsplay}),2,'.','');

${$myavgnet}= number_format((${$mynet}/${$roundsplay}),2,'.','');

$myfwaypct= number_format((${$myfways}/${$roundsplay})*100,2,'.','');

$mygirpct= number_format((${$mygir}/${$roundsplay})*100,2,'.','');

$mysandsavepct= number_format((${$mysandsave}/${$roundsplay})*100,2,'.','');

${$myavgputt}=number_format((${$myputts}/${$roundsplay}),2,'.','');

} else {

${$myavggross}=0;

${$myavgnet}=0;



}



$myavgputt=${$myavgputt};



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



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

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

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

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


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



//display@!!!!!!!!!

if (${$rankhole}==1) {

$color='#CC0000';

} elseif (${$rankhole}==18) {

$color='#99ccff';



} else {

$color='#FFFF99';



}

echo "<tr bgcolor='$color'><td class='menu-bg2'>

			<a href='javascript:void(0);' onClick=\"window.open('holecharts.php?hole=$hole&courseid=$courseid&rankhole=${$rankhole}&login_id=$login_id&myavggross=${$myavggross}&myavgnet=${$myavgnet}&allavggross=${$allavggross}&allavgnet=${$allavgnet}&allavgputt=${$allavgputt}&allfwaypct=$allfwaypct&allgirpct=$allgirpct&allsandsavepct=$allsandsavepct&myavgputt=$myavgputt&myfwaypct=$myfwaypct&mygirpct=$mygirpct&mysandsavepct=$mysandsavepct','HoleStats','scrollbars=yes,width=900,height=770,left=50,top=0')\">$hole</a>

</td><td>${$lengthhole}</td><td>${$indexhole}</td>";

echo "<td>${$parhole}</td><td>${$myavggross}</td><td>${$allavggross}</td><td>${$myavgnet}</td>

<td>${$allavgnet}</td>

<td>$allfwaypct %</td><td>$allgirpct %</td><td>$allsandsavepct %</td><td>${$allavgputt}</td><td>${$rankhole}</td>";

echo "</tr>";



//find grandtotals

$grandlength=$grandlength+${$lengthhole};

$grandpar=$grandpar+${$parhole};

$grandmygross=$grandmygross+${$myavggross};

$grandallgross=$grandallgross+${$allavggross};

$grandmynet=$grandmynet+${$myavgnet};

$grandallnet=$grandallnet+${$allavgnet};



$grandfwaypct=$grandfwaypct+$allfwaypct;

$grandgirpct=$grandgirpct+$allgirpct;

$grandsandsavepct=$grandsandsavepct+$allsandsavepct;

$grandputt=$grandputt+${$allavgputt};



} else {









}//endif holeexist







} while ($hole<18);





//finally some final cals

$grandavgfway=number_format(($grandfwaypct/18),2,'.','');

$grandavggir=number_format(($grandgirpct/18),2,'.','');

$grandavgsandsave=number_format(($grandsandsavepct/18),2,'.','');






echo "<tr><td>&nbsp;</td><td>$grandlength</td><td>INDEX</td>";

echo "<td>$grandpar</td><td>$grandmygross</td><td>$grandallgross</td><td>$grandmynet</td>

<td>$grandallnet</td><td>$grandavgfway %</td><td>$grandavggir %</td><td>$grandavgsandsave %</td><td>$grandputt</td>";

echo "</tr>";



echo "</table>";



} else {





$ranksql="select *  

					from courses 		 								  

					where courseid='$courseid'";

					$rankquery=mysql_query($ranksql);

				$rankrow=mysql_fetch_array($rankquery);

				$rankexist=mysql_numrows($rankquery);



$hole=0;

do {

$hole++;

extract($rankrow);



//this is for the basic info of the hole

$lengthhole=lengthhole.$hole;

$indexhole=indexhole.$hole;

$parhole=parhole.$hole;

//display@!!!!!!!!!

echo "<tr><td>

			$hole

</td><td>${$lengthhole}</td><td>${$indexhole}</td>";

echo "<td>${$parhole}</td><td>-</td><td>-</td><td>-</td>

<td>-</td><td>-</td><td>-</td><td>-</td><td>-</td>";

echo "</tr>";



} while ($hole<18);

echo "<tr><td>&nbsp;</td><td>$courselength</td><td>INDEX</td>";

echo "<td>$coursepar</td><td>-</td><td>-</td><td>-</td>

<td>-</td><td>-</td><td>-</td><td>-</td><td>-</td>";

echo "</tr>";



echo "</table>";

}//endif rankexist





} else {



$error="The Course ID exist! Please input another course id.";



} //endif courscheckeexist







}//endif courseid



?>



























<? showfooter(); ?>

Return current item: GolfstatsPHP