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

if ($HTTP_GET_VARS['userid']) {


//check if user has a game
$gamesql="Select *,date_format(date,'%d/%m/%Y') as real_date from games   
					where userid = '$userid'
					order by date desc";

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


//here we piggy back on the above statement to find the no of chipins
do {
$chipinhole=$gamerow['chipins'];
$chip_ins=$chip_ins+$chipinhole;

//find the game with the longest drive
$longdrive_game=$gamerow['longest_drive'];
$longdrive_id=$gamerow['gameid'];
if (($longdrive_game <> "na") && ($longdrive_game > $longdrive_cur)) {
$longdrive_cur=$longdrive_game;
$longdrive_cur_id=$longdrive_id;
}

} while ($gamerow=mysql_fetch_array($gamequery));

//check for WMD
//now check if this guy has WMD
$wmdsql="Select *
				from users_clubs a1
					where a1.userid = '$userid'";				
				$wmdquery=mysql_query($wmdsql);
				$wmdexist=mysql_numrows($wmdquery);

if ($wmdexist) {
$wmdrow=mysql_fetch_array($wmdquery);
extract($wmdrow);
} else {
$driver="NA";
$woods="NA";
$irons="NA";
$putter="NA";
$ball="NA";
$bag="NA";

}//endif wmdexist				
				
				
				
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<? showheader("Overall Statistics"); ?>

<p>

<?
if ($gameexist) {


//check if user has a game AGAIN
$gamesql="Select *,date_format(date,'%d/%m/%Y') as real_date from games  
					left join courses 
					ON games.courseid = courses.courseid 			 
					where games.userid = '$userid'
					order by date DESC";

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


//get all the stats from ranking table!
$statssql="Select * from ranking  
					where userid = '$userid'";

				$statsquery=mysql_query($statssql);
				$statsrow=mysql_fetch_array($statsquery);
				$statsexist=mysql_numrows($statsquery);

extract($statsrow);

$mugshot="mug_"."$userid".".jpg";
//<img src="images/<?echo $mugshot;
//notice i used td style=xxxx to override the CSS of vertical align = top

?>
<table width="90%" border=0>
<tr>
<td class=heading align=center>
<?echo $fullname; ?></td><td style="vertical-align:bottom;"><b>Weapons of Mass Destruction</b></td>
</tr>
<tr align="center">
<td style="vertical-align: middle;" align="center" width=15%>
<img src="images/<?echo $mugshot;?>" border="1">
</td>

<td align="left" width=85%>
<?
echo "<table border=1>"; 
echo "<tr class=bg4><td class=menu-bg2 width=15%>Driver</td><td>$driver</td></tr>";
echo "<tr class=bg4><td class=menu-bg2>Woods</td><td>$woods</td></tr>";
echo "<tr class=bg4><td class=menu-bg2>Irons</td><td>$irons</td></tr>";
echo "<tr class=bg4><td class=menu-bg2>Putter</td><td>$putter</td></tr>";
echo "<tr class=bg4><td class=menu-bg2>Bag</td><td>$bag</td></tr>";
echo "<tr class=bg4><td class=menu-bg2>Primary Balls</td><td>$ball</td></tr>";
echo "</table>";
?>
</td>

</tr>
</table>

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

<tr>
<td width="50%">

<p>
<table border=0 width=100%>
<tr class="menu-bg"><td class="menu-bg"><b>Player Statistics</b></td></tr>
</table><p>


<?


$substatssql="Select * from substats where userid='$userid'";

				$substatsquery=mysql_query($substatssql);
				$substatsrow=mysql_fetch_array($substatsquery);
				$substatsexist=mysql_numrows($substatsquery);

				//howmany players				
$noplayers=$substatsexist;
 
extract($substatsrow);

//SEE fields from ranking table
$showfield="Show fields from ranking";
$showfieldquery=mysql_query($showfield);
$showfieldrow=mysql_fetch_array($showfieldquery);				
$showfieldexist=mysql_numrows($showfieldquery);

$fieldcount=0;

do {
$fieldname=$showfieldrow['Field'];

if ($fieldcount>1) {

if (($fieldname == 'puttavg') || ($fieldname == 'puttround') || ($fieldname == 'avgscore') 
|| ($fieldname == 'net_avgscore')|| ($fieldname == 'par3perf')|| ($fieldname == 'par4perf')
|| ($fieldname == 'par5perf')|| ($fieldname == 'net_par3perf')|| ($fieldname == 'net_par4perf')
|| ($fieldname == 'net_par5perf') ) {



$ranksql="Select * from ranking
					ORDER by $fieldname ASC";
} else {
$ranksql="Select * from ranking
					ORDER by $fieldname DESC";

}
				$rankquery=mysql_query($ranksql);
				$rankrow=mysql_fetch_array($rankquery);
				$rankexist=mysql_numrows($rankquery);

//OK NOW to find the ranking!!

$count=1;
$fieldname_rank=$fieldname._rank;
do {

$rank_userid=$rankrow['userid'];
//1.Driving Distance

if ($rank_userid == $userid) {
${$fieldname_rank}=$count;

} //endif userid is loginid
$count++;
} while ($rankrow=mysql_fetch_array($rankquery)); 				


} //endif fieldcount not 0

$fieldcount++;
} while ($showfieldrow=mysql_fetch_array($showfieldquery));



#########Tournament Stats#################
//ok lets get the tourney stats!

################Count tourney stats##############################3
//count how many tournaments
$notourneysql="Select * from games  
					where userid = '$userid' and tournament=1;";

				$notourneyquery=mysql_query($notourneysql);
				$notourneyrow=mysql_fetch_array($notourneyquery);
				$notourneyexist=mysql_numrows($notourneyquery);

$tourneywins="0";
$tourney3="0";
$tourney5="0";	
$tourneybest=100;
//loop through to get the stats

if ($notourneyexist) {
do {
extract($notourneyrow);
if ($tourneyplace==1) {
$tourneywins=$tourneywins+1;
}

if ($tourneyplace<=3) {
$tourney3=$tourney3+1;
}

if ($tourneyplace<=5) {
$tourney5=$tourney5+1;
}

if ($tourneyplace < $tourneybest) {
$tourneybest=$tourneyplace;
}

} while ($notourneyrow=mysql_fetch_array($notourneyquery)); 

//this is to count the averages
$notourneysql="Select sum(tourneyplace) as sumplace,sum(gross_score) as sumgross,sum(net_score) as sumnet from games  
					where userid = '$userid' and tournament=1;";

				$notourneyquery=mysql_query($notourneysql);
				$notourneyrow=mysql_fetch_array($notourneyquery);

extract($notourneyrow);
$tourneyavg=$sumplace/$notourneyexist;
$tourneygrossavg=$sumgross/$notourneyexist;
$tourneynetavg=$sumnet/$notourneyexist;
 } else {

$tourneywins="NA";
$tourney3="NA";
$tourney5="NA";
$tourneybest="NA";
$tourneyavg="NA";
$tourneygrossavg="NA";
$tourneynetavg="NA";

} //endif notourney exist
echo "<table border=1 width=50%>";
echo "<tr class='menu-bg'>";
echo "<td>Tournament Stats</td><td width=30%>&nbsp;</td>";
echo "</tr>";


echo "<tr><td class='menu-bg2'>Tournaments Played</td><td>$notourneyexist</td></tr>";
echo "<tr><td class='menu-bg2'>Wins</td><td>$tourneywins</td></tr>";
echo "<tr><td class='menu-bg2'>Top 3s</td><td>$tourney3</td></tr>";
echo "<tr><td class='menu-bg2'>Top 5s</td><td>$tourney5</td></tr>";
echo "<tr><td class='menu-bg2'>Best Finish</td><td>$tourneybest</td></tr>";
echo "<tr><td class='menu-bg2'>Average Placing</td><td>".round($tourneyavg,2)."</td></tr>";
echo "<tr><td class='menu-bg2'>Average Gross</td><td>".round($tourneygrossavg,2)."</td></tr>";
echo "<tr><td class='menu-bg2'>Average Net</td><td>".round($tourneynetavg,2)."</td></tr>";

echo "</table><p>";



########################End tourney stats#######################

?>
<p>
<table border=1>
<tr class="menu-bg">
<td>Standard Stats</td><td>&nbsp;</td><td>Rank</td><td>Additional</td>
</tr>


<?
echo "<tr><td class='menu-bg2'><a href='#' title=\"AverageDrive\" onClick=\"window.open('statranks.php?topstats=ddistance&title=Average Drive','AverageDrive','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Driving Distance</a></td><td> $ddistance $measureshort</td><td>$ddistance_rank/$rankexist</td>
<td>Tot.Dist:$total_drive_distance Tot.Drvs:$total_drive</td></tr>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"DrivingAccuracy\" onClick=\"window.open('statranks.php?topstats=pctdaccuracy&title=Drive Accuracy','DrivingAccuracy','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Driving Accuracy Percentage</a></td><td> $daccuracy %</td><td>$daccuracy_rank/$rankexist</td>
<td>Fwys Hit:$total_fairways_hit Poss.Fwys:$poss_fairways</td></tr>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"LongestDrive\" onClick=\"window.open('statranks.php?topstats=dlongest&title=Longest Drive','LongestDrive','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Longest Drive</a></td><td>$dlongest $measureshort</td><td>$dlongest_rank/$rankexist</td><td>Game:<a href='#' title=\"$longdrive_cur_id\" onClick=\"window.open('players3.php?userid=$userid&gameid=$longdrive_cur_id','$longdrive_cur_id','left=100,top=0,height=730,width=620,scrollbars=yes');return false;\">$longdrive_cur_id</a></td></tr>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"GIR\" onClick=\"window.open('statranks.php?topstats=pctgirpct&title=Greens in Regulation','GIR','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Greens in Regulation Percentage</a></td><td> $girpct %</td><td>$girpct_rank/$rankexist</td>
<td>Tot.GIR:$total_gir Holes Putted:$total_holes_putt</td></tr>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Sand Save\" onClick=\"window.open('statranks.php?topstats=pctsandsavepct&title=Sand Saves','sandsave','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Sand Save Percentage</a></td><td> $sandsavepct %</td><td>$sandsavepct_rank/$rankexist</td>
<td>Tot.Bunkers:$total_bunker Holes Saved:$total_sandsave</td></tr>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Putting Average\" onClick=\"window.open('statranks.php?topstats=puttavg&title=Putts per Hole','PuttingAverage','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Putting Average</a></td><td> $puttavg</td><td>$puttavg_rank/$rankexist</td>
<td>Tot.Putts:$total_putts2 Holes Putted:$total_holes_putt</td></tr>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Putts per round\" onClick=\"window.open('statranks.php?topstats=puttround&title=Putts per Round','Puttsperround','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Putts per round</a></td><td> $puttround</td><td>$puttround_rank/$rankexist</td>
<td>Avg.Putt:$puttavg Rounds:$total_putt_rounds</td></tr>";
echo "<tr><td class='menu-bg2'>Chip Ins Made</td><td> $chip_ins</td><td>-</td>
<td>-</td></tr>";

echo "</table><p>";

echo "<table border=1>";
echo "<tr class='menu-bg'><td>Scoring</td><td>Gross</td><td>Rank</td><td>Additional</td><td>Net</td><td>Rank</td><td>Additional</td></tr>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Total Double Eagles\" onClick=\"window.open('statranks.php?topstats=gn_totaldoubleeagles&title=Total Double Eagles','TotalDoubleEagles','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Total Double Eagles</a></td><td>$totaldoubleeagles</td><td>$totaldoubleeagles_rank/$rankexist</td><td>-</td>
<td>$net_totaldoubleeagles</td><td>$net_totaldoubleeagles_rank/$rankexist</td><td>-</td>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Total Aces\" onClick=\"window.open('statranks.php?topstats=gn_totalholeinone&title=Total Aces','TotalAces','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Total Aces</a></td><td>$totalholeinone</td><td>$totalholeinone_rank/$rankexist</td><td>-</td>
<td>$net_totalholeinone</td><td>$net_totalholeinone_rank/$rankexist</td><td>-</td>";

echo "<tr><td class='menu-bg2'><a href='#' title=\"Total Eagles\" onClick=\"window.open('statranks.php?topstats=gn_totaleagles&title=Total Eagles','TotalEagles','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Total Eagles</a></td><td>$totaleagles</td><td>$totaleagles_rank/$rankexist</td><td>-</td>
<td>$net_totaleagles</td><td>$net_totaleagles_rank/$rankexist</td><td>-</td>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Birdie Average\" onClick=\"window.open('statranks.php?topstats=gn_birdieavg&title=Birdie Average','BirdieAverage','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Birdie Average</a></td><td>$birdieavg/round</td><td>$birdieavg_rank/$rankexist</td><td>Tot.Birdies:$total_birdies</td>
<td>$net_birdieavg/round</td><td>$net_birdieavg_rank/$rankexist</td><td>Tot.Birdies:$net_total_birdies</td>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Par Average\" onClick=\"window.open('statranks.php?topstats=gn_paravg&title=Par Average','ParAverage','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Par Average</a></td><td>$paravg/round</td><td>$paravg_rank/$rankexist</td><td>Tot.Pars:$total_par</td>
<td>$net_paravg/round</td><td>$net_paravg_rank/$rankexist</td><td>Tot.Pars:$net_total_par</td>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Score Average\" onClick=\"window.open('statranks.php?topstats=gn_avgscore&title=Average Score','ScoreAverage','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Average Score</a></td><td>$avgscore/round</td><td>$avgscore_rank/$rankexist</td><td>Tot.Score:$total_gross</td>
<td>$net_avgscore/round</td><td>$net_avgscore_rank/$rankexist</td><td>Tot.Score:$total_net</td>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Par Breakers\" onClick=\"window.open('statranks.php?topstats=gnpparbreakers&title=Par Breakers','ParBreakers','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Par Breakers</a></td><td>$parbreakers %</td><td>$parbreakers_rank/$rankexist</td><td>Bird/Eagl:$total_parbreak <br>Tot.Holes:$total_holes</td>
<td>$net_parbreakers %</td><td>$net_parbreakers_rank/$rankexist</td><td>Bird/Eagl:$net_total_parbreak <br>Tot.Holes:$total_holes</td>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Par 3 Birdies\" onClick=\"window.open('statranks.php?topstats=gnppar3birdies&title=Par 3 Birdies','Par3Birdies','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Par 3 Birdies</a></td><td>$par3birdies %</td><td>$par3birdies_rank/$rankexist</td><td>Par3.Bird:$par3_birdies <br>Tot.Par3:$total_par3</td>
<td>$net_par3birdies %</td><td>$net_par3birdies_rank/$rankexist</td><td>Par3.Bird:$net_par3_birdies <br>Tot.Par3:$total_par3</td>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Par 4 Birdies\" onClick=\"window.open('statranks.php?topstats=gnppar4birdies&title=Par 4 Birdies','Par4Birdies','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Par 4 Birdies</a></td><td>$par4birdies %</td><td>$par4birdies_rank/$rankexist</td><td>Par4.Bird:$par4_birdies <br>Tot.Par4:$total_par4</td>
<td>$net_par4birdies %</td><td>$net_par4birdies_rank/$rankexist</td><td>Par4.Bird:$net_par4_birdies <br>Tot.Par4:$total_par4</td>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Par 5 Birdies\" onClick=\"window.open('statranks.php?topstats=gnppar5birdies&title=Par 5 Birdies','Par5Birdies','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Par 5 Birdies</a></td><td>$par5birdies %</td><td>$par5birdies_rank/$rankexist</td><td>Par5.Bird:$par5_birdies <br>Tot.Par5:$total_par5</td>
<td>$net_par5birdies %</td><td>$net_par5birdies_rank/$rankexist</td><td>Par5.Bird:$net_par5_birdies <br>Tot.Par5:$total_par5</td>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Par 3 Pars\" onClick=\"window.open('statranks.php?topstats=gnppar3pars&title=Par 3 Pars','Par3Pars','left=100,top=0,height=430,width=630,scrollbars=yes');return false;\">Par 3 Pars</a></td><td>$par3pars %</td><td>$par3pars_rank/$rankexist</td><td>Par3.Pars:$par3_pars <br>Tot.Par3:$total_par3</td>
<td>$net_par3pars %</td><td>$net_par3pars_rank/$rankexist</td><td>Par3.Pars:$net_par3_pars <br>Tot.Par3:$total_par3</td>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Par 4 Pars\" onClick=\"window.open('statranks.php?topstats=gnppar4pars&title=Par 4 Pars','Par4Pars','left=100,top=0,height=430,width=630,scrollbars=yes');return false;\">Par 4 Pars</a></td><td>$par4pars %</td><td>$par4pars_rank/$rankexist</td><td>Par4.Pars:$par4_pars <br>Tot.Par4:$total_par4</td>
<td>$net_par4pars %</td><td>$net_par4pars_rank/$rankexist</td><td>Par4.Pars:$net_par4_pars <br>Tot.Par4:$total_par4</td>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Par 5 Pars\" onClick=\"window.open('statranks.php?topstats=gnppar5pars&title=Par 5 Pars','Par5Pars','left=100,top=0,height=430,width=630,scrollbars=yes');return false;\">Par 5 Pars</a></td><td>$par5pars %</td><td>$par5pars_rank/$rankexist</td><td>Par5.Pars:$par5_pars <br>Tot.Par5:$total_par5</td>
<td>$net_par5pars %</td><td>$net_par5pars_rank/$rankexist</td><td>Par5.Pars:$net_par5_pars <br>Tot.Par5:$total_par5</td>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Par 3 Average\" onClick=\"window.open('statranks.php?topstats=gn_par3perf&title=Par 3 Average','Par3Average','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Par 3 Performance</a></td><td>$par3perf</td><td>$par3perf_rank/$rankexist</td><td>Par3.Score:$total_par3_scores <br>Tot.Par3:$total_par3</td>
<td>$net_par3perf </td><td>$net_par3perf_rank/$rankexist</td><td>Par3.Score:$net_par3_scores <br>Tot.Par3:$total_par3</td>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Par 4 Average\" onClick=\"window.open('statranks.php?topstats=gn_par4perf&title=Par 4 Average','Par4Average','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Par 4 Performance</a></td><td>$par4perf</td><td>$par4perf_rank/$rankexist</td><td>Par4.Score:$total_par4_scores <br>Tot.Par4:$total_par4</td>
<td>$net_par4perf </td><td>$net_par4perf_rank/$rankexist</td><td>Par4.Score:$net_par4_scores <br>Tot.Par4:$total_par4</td>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Par 5 Average\" onClick=\"window.open('statranks.php?topstats=gn_par5perf&title=Par 5 Average','Par5Average','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Par 5 Performance</a></td><td>$par5perf</td><td>$par5perf_rank/$rankexist</td><td>Par5.Score:$total_par5_scores <br>Tot.Par5:$total_par5</td>
<td>$net_par5perf </td><td>$net_par5perf_rank/$rankexist</td><td>Par5.Score:$net_par5_scores <br>Tot.Par5:$total_par5</td>";
echo "<tr><td class='menu-bg2'><a href='#' title=\"Scrambling\" onClick=\"window.open('statranks.php?topstats=gnpscrambling&title=Scrambling','Scrambling','left=100,top=0,height=630,width=430,scrollbars=yes');return false;\">Scrambling</a></td><td>$scrambling %</td><td>$scrambling_rank/$rankexist</td><td>Scrambled:$scrambled_holes GIR.Miss:$missed_gir</td>
<td>$net_scrambling % </td><td>$net_scrambling_rank/$rankexist</td><td>Scrambled:$net_scrambled_holes GIR.Miss:$missed_gir</td>";

echo "</table>";





echo "</td>";
echo "<td>";
?>
<table border=1>
<tr>
<td class="menu-bg" colspan=6><b>Scorecards</b> [click scorecard to view]</td>
</tr>
<tr class="menu-bg">

<td>#</td><td>Gross</td><td>Net</td><td>Course</td><td>Date</td><td>Scorecard</td>
</tr>

<?
$countno=1;
//OK, populate the drop down on the row.
do {

extract($gamerow);
echo "<tr><td align='center' class='menu-bg2'>$countno</td><td>$gross_score</td><td>$net_score</td>";
echo "<td>$coursename</td><td>$real_date</td>
<td><a href='#' title=\"$gameid\" onClick=\"window.open('players3.php?userid=$userid&gameid=$gameid','$gameid','left=100,top=0,height=730,width=620,scrollbars=yes');return false;\">$gameid</a></td>"; 


echo "</tr>";

$countno++;																																								 
																																															
} while ($gamerow=mysql_fetch_array($gamequery));
 //endwhile


?>

</table>


<?
echo "</td>";
echo "</tr>";
echo "</table>";



} else {

echo "Player selected doesn't have any scorecards yet. Please enter score cards <a href='statsmain.php'>here</a>.";


} //endif gameexist


} else {

echo "Application error. Please contact system administrator.";

}//endif $HTTP_GET_VARS
?>


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