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

include("dbasecon.inc.php");

include("session.inc.php");

include ("header.php");

include ("statscoursefunctions.inc.php");




//check if any games exist
$gamessql="select * from games";
				$gamesquery=mysql_query($gamessql);
				$gamesrow=mysql_fetch_array($gamesquery);
				$gamesexist=mysql_numrows($gamesquery);
				
//first lets rank each course

$ranksql="select * from courses  

					order by courseid desc";



				$rankquery=mysql_query($ranksql);

				$rankrow=mysql_fetch_array($rankquery);

				$rankexist=mysql_numrows($rankquery);

if ($rankexist) {

do {

extract($rankrow);





//counttotal average score!

$avgcoursestats=explode(",",avgcoursestats($courseid));



if (!$avgcoursestats[0]) {

$avgcoursestats[0]="na";

}

if (!$avgcoursestats[1]) {

$avgcoursestats[1]="na";

}





$updatesql="UPDATE courses SET avgcoursegross='$avgcoursestats[0]', avgcoursenet='$avgcoursestats[1]'

					 WHERE courseid='$courseid'";

		$updatequery=mysql_query($updatesql);		



		

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







######After update, we still need to rank it mate!###############



$ranksql="select courseid,avgcoursegross,avgcoursenet 

					from courses 		 								  

					order by avgcoursenet DESC , avgcoursegross DESC";				

				

				$rankquery=mysql_query($ranksql);

				$rankrow=mysql_fetch_array($rankquery);

				$rankexist=mysql_numrows($rankquery);

$rankstatus=0;

do {

$rankstatus++;

$rankcourseid=$rankrow['courseid'];



${rank.$rankcourseid}=$rankstatus;

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

				



} //endif $rankrow











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

//get list of courses



$coursesql="select * from courses   

					order by avgcoursenet desc,avgcoursegross desc,courses.coursename desc";



				$coursequery=mysql_query($coursesql);

				$courserow=mysql_fetch_array($coursequery);

				$courseexist=mysql_numrows($coursequery);



?>



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



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



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

<? if ($gamesexist) { ?>

<!-----------------NEXT TD---------------------->

<form method="post" action="<?=$PHP_SELF?>">





<table width="50%">

<tr>

<td><b>Par 3 Stats:</b></td><td><b>Par 4 Stats:</b></td><td><b>Par 5 Stats:</b></td></tr>

<tr>

<td>

<select name="top53">

<option value="gn_avggross"> Select Top 5... </option>

<option value="gn_avggross" <?if ($top53=='gn_avggross') {echo 'SELECTED';}?>> Average Gross Score</option>

<option value="gn_avgnet" <?if ($top53=='gn_avgnet') {echo 'SELECTED';}?>>Average Net Score</option>

<option value="gnpfwayhitpct" <?if ($top53=='gnpfwayhitpct') {echo 'SELECTED';}?>>Fairway Hit</option>

<option value="gnpgirpct" <?if ($top53=='gnpgirpct') {echo 'SELECTED';}?>>GIR</option>

<option value="gnpsandsavepct" <?if ($top53=='gnpsandsavepct') {echo 'SELECTED';}?>>Sand Save</option>

<option value="avgputt" <?if ($top53=='avgputt') {echo 'SELECTED';}?>>Putts/Hole</option>

<option value="holelength" <?if ($top53=='holelength') {echo 'SELECTED';}?>>Hole Distance</option>

</select>

<input type="Submit" name="statssel3" value="Go>>">



</td>



<td>

<select name="top54">

<option value="gn_avggross"> Select Top 5... </option>

<option value="gn_avggross" <?if ($top54=='gn_avggross') {echo 'SELECTED';}?>> Average Gross Score</option>

<option value="gn_avgnet" <?if ($top54=='gn_avgnet') {echo 'SELECTED';}?>>Average Net Score</option>

<option value="gnpfwayhitpct" <?if ($top54=='gnpfwayhitpct') {echo 'SELECTED';}?>>Fairway Hit</option>

<option value="gnpgirpct" <?if ($top54=='gnpgirpct') {echo 'SELECTED';}?>>GIR</option>

<option value="gnpsandsavepct" <?if ($top54=='gnpsandsavepct') {echo 'SELECTED';}?>>Sand Save</option>

<option value="avgputt" <?if ($top54=='avgputt') {echo 'SELECTED';}?>>Putts/Hole</option>

<option value="holelength" <?if ($top54=='holelength') {echo 'SELECTED';}?>>Hole Distance</option>

</select>

<input type="Submit" name="statssel4" value="Go>>">



</td>



<td>

<select name="top55">

<option value="gn_avggross"> Select Top 5... </option>

<option value="gn_avggross" <?if ($top55=='gn_avggross') {echo 'SELECTED';}?>> Average Gross Score</option>

<option value="gn_avgnet" <?if ($top55=='gn_avgnet') {echo 'SELECTED';}?>>Average Net Score</option>

<option value="gnpfwayhitpct" <?if ($top55=='gnpfwayhitpct') {echo 'SELECTED';}?>>Fairway Hit</option>

<option value="gnpgirpct" <?if ($top55=='gnpgirpct') {echo 'SELECTED';}?>>GIR</option>

<option value="gnpsandsavepct" <?if ($top55=='gnpsandsavepct') {echo 'SELECTED';}?>>Sand Save</option>

<option value="avgputt" <?if ($top55=='avgputt') {echo 'SELECTED';}?>>Putts/Hole</option>

<option value="holelength" <?if ($top55=='holelength') {echo 'SELECTED';}?>>Hole Distance</option>

</select>

<input type="Submit" name="statssel5" value="Go>>">

</form>

</td>



</tr>

</table>



<table border=1>


<?
} //endif courseexists

?>

<?

//alrite, here comes the stats!!!!!!!!

if ($HTTP_POST_VARS['statssel3']) {



#####################PAR 3##########################3

if ($HTTP_POST_VARS['top53']) {

echo "<tr class='menu-bg'><td>Rank<td>Hole #</td><td>Coursename</td><td>Par</td><td>Value</td></tr>";



if (($top53=="avgputt") || ($top53=="gn_avggross") || ($top53=="gn_avgnet") || ($top53=="holelength")) {

$seq="DESC";

} else {

$seq="ASC";

} //endif seq



//ok, lets format the gn stats!

if ((substr($top53,0,3) == "gn_") || (substr($top53,0,3) == "gnp"))  {



//get rid of the gn

$newtop5=substr($top53,3);



//make % sign for all starting with gnp

if (substr($top53,0,3) == "gnp") { $pct="%"; } else {$pct="";} 

} else {

$newtop5=$top53;

}





$ranksql="Select holerank.courseid,holeid,par,$newtop5,coursename

					from holerank left join courses on holerank.courseid = courses.courseid

					where holerank.par='3' 

					order by $newtop5 $seq LIMIT 5";

			$rankquery=mysql_query($ranksql);

				$rankrow=mysql_fetch_array($rankquery);

				$rankexist=mysql_numrows($rankquery);





$countno=0;

do {

extract($rankrow);

$countno++;

echo "<tr><td>$countno</td><td>$holeid</td><td><a href='statscourse2.php?courseid=$courseid&action=view'>$coursename</a></td><td>$par</td><td>${$newtop5} $pct</td></tr>";





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





}//endif http_post_vars





##################END PAR 3#####################################











} //endif statssel







if ($HTTP_POST_VARS['statssel4']) {



#####################PAR 4##########################3

if ($HTTP_POST_VARS['top54']) {

echo "<tr class='menu-bg'><td>Rank<td>Hole #</td><td>Coursename</td><td>Par</td><td>Value</td></tr>";



if (($top54=="avgputt") || ($top54=="gn_avggross") || ($top54=="gn_avgnet") || ($top54=="holelength")) {

$seq="DESC";

} else {

$seq="ASC";

} //endif seq



//ok, lets format the gn stats!

if ((substr($top54,0,3) == "gn_") || (substr($top54,0,3) == "gnp"))  {



//get rid of the gn

$newtop5=substr($top54,3);



//make % sign for all starting with gnp

if (substr($top54,0,3) == "gnp") { $pct="%"; } else {$pct="";} 

} else {

$newtop5=$top54;

}





$ranksql="Select holerank.courseid,holeid,par,$newtop5,coursename

					from holerank left join courses on holerank.courseid = courses.courseid

					where holerank.par='4' 

					order by $newtop5 $seq LIMIT 5";

			$rankquery=mysql_query($ranksql);

				$rankrow=mysql_fetch_array($rankquery);

				$rankexist=mysql_numrows($rankquery);





$countno=0;

do {

extract($rankrow);

$countno++;

echo "<tr><td>$countno</td><td>$holeid</td><td><a href='statscourse2.php?courseid=$courseid&action=view'>$coursename</a></td><td>$par</td><td>${$newtop5} $pct</td></tr>";





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





}//endif http_post_vars





##################END PAR 4#####################################











} //endif statssel4



if ($HTTP_POST_VARS['statssel5']) {



#####################PAR 5##########################3

if ($HTTP_POST_VARS['top55']) {

echo "<tr class='menu-bg'><td>Rank<td>Hole #</td><td>Coursename</td><td>Par</td><td>Value</td></tr>";



if (($top55=="avgputt") || ($top55=="gn_avggross") || ($top55=="gn_avgnet") || ($top55=="holelength")) {

$seq="DESC";

} else {

$seq="ASC";

} //endif seq



//ok, lets format the gn stats!

if ((substr($top55,0,3) == "gn_") || (substr($top55,0,3) == "gnp"))  {



//get rid of the gn

$newtop5=substr($top55,3);



//make % sign for all starting with gnp

if (substr($top55,0,3) == "gnp") { $pct="%"; } else {$pct="";} 

} else {

$newtop5=$top55;

}





$ranksql="Select holerank.courseid,holeid,par,$newtop5,coursename

					from holerank left join courses on holerank.courseid = courses.courseid

					where holerank.par='5' 

					order by $newtop5 $seq LIMIT 5";

			$rankquery=mysql_query($ranksql);

				$rankrow=mysql_fetch_array($rankquery);

				$rankexist=mysql_numrows($rankquery);





$countno=0;

do {

extract($rankrow);

$countno++;

echo "<tr><td>$countno</td><td>$holeid</td><td><a href='statscourse2.php?courseid=$courseid&action=view'>$coursename</a></td><td>$par</td><td>${$newtop5} $pct</td></tr>";





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





}//endif http_post_vars





##################END PAR 5#####################################











} //endif statssel5













































?>



<tr>

<td>





</td>

</tr>



</table>





<b class="error">Click on the Course ID for details.</b><p>





<form  method="post" action="<? echo $PHP_SELF; ?>">



<u><b>Total Courses created: <? echo $courseexist; ?></b></u>



<p>

<?

if ($courseexist) {



?>



<table border=1>

<tr class="menu-bg">

<td>Course ID</td><td>Course</td><td>Location</td><td>Rating</td><td>Slope</td><td>Par</td><td>Length</td>

<td>Your.Gross</td><td>Avg.Gross</td><td>Your.Net</td><td>Avg.Net</td><td>Rank</td>





</tr>









<?







//OK, populate the drop down on the row.

do {

extract($courserow);











$rankcourse=rank.$courseid;























//count your average score!

$yourcoursestats=explode(",",yourcoursestats($login_id,$courseid));



if (!$yourcoursestats[0]) {

$yourcoursestats[0]="na";

}

if (!$yourcoursestats[1]) {

$yourcoursestats[1]="na";

}







echo "<tr><td class='menu-bg2'><a href='statscourse2.php?courseid=$courseid&action=view'>$courseid</a></td><td>$coursename</td><td>$coursestate</td>";

echo "<td>$courserating</td><td>$sloperating</td><td>$coursepar</td>";

echo "<td>$courselength $measureshort</td>";

echo "<td>$yourcoursestats[0]</td>";

echo "<td>$avgcoursegross</td>";

echo "<td>$yourcoursestats[1]</td>";

echo "<td>$avgcoursenet</td>";

echo "<td>${$rankcourse}</td>";



echo "</tr>";





																																															

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

 //endwhile





echo "</table>";

















} else {



echo "<b>There are no courses available. <a href='course.php'>Create one!</a></b>"; 

}

?>







<? showfooter(); ?>

Return current item: GolfstatsPHP