Location: PHPKode > projects > GolfstatsPHP > golfstatsphp_3.0/statranks.php
<?
include("dbasecon.inc.php");
include("session.inc.php");
include ("header1.php");
include ("score_functions.inc.php");
?>
<HTML><HEAD><TITLE><?= $title ?></TITLE>

	<link rel="StyleSheet" href="style.css" type="text/css">

	</HEAD>

	<body>
	
	
<FORM> 

<INPUT type="button" value="Close Rankings" onClick="window.close()"> 

</FORM> 
	<?

if ($HTTP_GET_VARS['topstats']) {

echo "<h1>$title</h1>";
$gamesql="Select *,date_format(date,'%d/%m/%Y') as real_date from games  
					left join courses
					ON games.courseid = courses.courseid
					order by gross_score, net_score desc";

				$gamequery=mysql_query($gamesql);
				$gamerow=mysql_fetch_array($gamequery);
				$gameexist=mysql_numrows($gamequery);

if (($topstats=="puttavg") || ($topstats=="puttround") || ($topstats=="gn_avgscore") || ($topstats=="gn_par3perf")
||($topstats=="gn_par4perf")||($topstats=="gn_par5perf")) {

$seq="ASC";
} else {
$seq="DESC";
} //endif seq


//ok if there are players only work!
if ($gameexist) {


//ok, lets format the gn stats!
if ((substr($topstats,0,3) == "gn_") || (substr($topstats,0,3) == "gnp"))  {

//get rid of the gn
$newtopstats=substr($topstats,3);
$netscore=net_.$newtopstats;

//make % sign for all starting with gnp
if (substr($topstats,0,3) == "gnp") { $pct="%"; } else {$pct="";} 
echo "<table border=1>";
echo "<tr class='menu-bg'><td>Rank<td>Name</td><td>Handicap</td><td>Gross</td><td>Net</td></tr>";

$ranksql="Select ranking.userid as userid2,name as name2,surname as surname2,handicap,$newtopstats,$netscore 
					from ranking left join users_tour on ranking.userid=users_tour.userid 
					order by $newtopstats $seq, $netscore $seq																";
			$rankquery=mysql_query($ranksql);
				$rankrow=mysql_fetch_array($rankquery);
				$rankexist=mysql_numrows($rankquery);

$countno=0;
do {
extract($rankrow);

//lets make sure this user has a game first!
$usersql="Select * from games where userid='$userid2'";

				$userquery=mysql_query($usersql);
				$userrow=mysql_fetch_array($userquery);
				$userexist=mysql_numrows($userquery);

if ($userexist) {				
				

$fullname2=$name2." ".$surname2;
$countno++;
echo "<tr class=bg4><td>$countno</td><td><a href='players2.php?userid=$userid2&action=details&fullname=$fullname2'>$fullname2</a></td><td>$handicap</td><td>${$newtopstats} $pct</td><td>${$netscore} $pct</td></tr>";


} //endif userexist

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

} else {

//ok, lets format the gn stats!
if (substr($topstats,0,3) == "pct") { 

$pct1="%";
$topstats=substr($topstats,3);

 } else {$pct1="";} 


$ranksql="Select ranking.userid as userid2,name as name2,surname as surname2,handicap,$topstats 
					from ranking left join users_tour on ranking.userid=users_tour.userid 
					where $topstats<>'0'  
					order by $topstats $seq";
			$rankquery=mysql_query($ranksql);
				$rankrow=mysql_fetch_array($rankquery);
				$rankexist=mysql_numrows($rankquery);

//only if there are data only work!
if ($rankexist) {
				
echo "<table border=1>";
echo "<tr class='menu-bg'><td>Rank<td>Name</td><td>Handicap</td><td>Value</td></tr>";




$countno=0;
do {
extract($rankrow);

//lets make sure this user has a game first!
$usersql="Select * from games where userid='$userid2'";

				$userquery=mysql_query($usersql);
				$userrow=mysql_fetch_array($userquery);
				$userexist=mysql_numrows($userquery);

if ($userexist) {				
				
				
$fullname2=$name2." ".$surname2;
$countno++;
echo "<tr class=bg4><td>$countno</td><td><a href='players2.php?userid=$userid2&action=details&fullname=$fullname2'>$fullname2</a></td><td>$handicap</td><td>${$topstats} $pct1</td></tr>";


} //endif Userexist


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



//echo $ranksql;

} else {

echo "There is not enough data for ranking.";
}//endif rankexist



}//endif topstats is gn



} else {


echo "<tr><td>No Players defined</td></tr>";

} //endif gamerow








} else {
$topstats="gn_avgscore";

}//endif http_post_vars





?>








</tr>

</table>





<? showfooter(); ?>
Return current item: GolfstatsPHP