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

include("dbasecon.inc.php");

include("session.inc.php");

include ("header.php");

include ("statscoursefunctions.inc.php");

/*
Formula as follows

Tournament Wins=x * 5
Top 3=x * 3
Top 5=x * 1

Drive Distance=x/100
Driving Accuracy=x/20

Average gross score=500/x
Average Net score=300/x
GIR=x/20

Putting Average=5/x

Eagles=x * 5
Net Eagles=x/(no of games/2)

Double Eagles=x * 10
Net Double Eagles=x * 3

Hole In one=x * 5
Net Hole in One=x/(no of games/2)


Gross Birdie=x * 2
Net Birdie=x
Gross Par=x
Net Par=x/2
Gross Parbreaker=x
Net Parbreakers=x/10

Scrambling=x/10
Net Scrambling=x/20



*/

//get list of players
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">



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

<?
$allusersql="Select distinct(a.userid) as alluserid,a.name as allname,a.surname as allsurname  
						from users_tour a LEFT JOIN games b
						on a.userid=b.userid  
						order by allname ASC";

				$alluserquery=mysql_query($allusersql);
				$alluserrow=mysql_fetch_array($alluserquery);

//Now go through each ranking of each player

do {
extract($alluserrow);


//count the rounds played
//count how many rounds 
$nogamesql="Select * from games  
					where userid = '$alluserid'";

				$nogamequery=mysql_query($nogamesql);
				$nogamerow=mysql_fetch_array($nogamequery);
				$nogameexist=mysql_numrows($nogamequery);

if ($nogameexist) {				
				
$gamesfactor=$nogameexist/2;



$statssql="Select * from ranking  
					where userid = '$alluserid'";

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

extract ($statsrow);

//Now start stats. Remember we must take into account how many stats are used
$nostats=0;
//1.calculate the points for average distance

//drive
if ($ddistance>0) {
$ddistancepts=$ddistance/100;
$nostats=$nostats+1;
} else {$ddistancepts=0;}

//accuracy
if ($daccuracy>0) {
$daccuracypts=$daccuracy/20;
$nostats=$nostats+1;
} else {$daccuracypts=0;}

//gir
if ($girpct>0) {
$girpctpts=$girpct/20;
$nostats=$nostats+1;
} else {$girpctpts=0;}

//average putts
if ($puttavg>0) {
$puttavgpts=5/$puttavg;
$nostats=$nostats+1;
} else {$puttavgpts=0;}



//total eagles
$totaleaglespts=5*$totaleagles;
$nostats=$nostats+1;

//total net eagles
$net_totaleaglespts=$net_totaleagles/$gamesfactor;
$nostats=$nostats+1;

//total double eagles
$totaldoubleeaglespts=10*$totaldoubleeagles;
$nostats=$nostats+1;

//total net double eagles
$net_totaldoubleeaglespts=3*$net_totaldoubleeagles;
$nostats=$nostats+1;

//total aces
$totalholeinonepts=5*$totalholeinone;
$nostats=$nostats+1;

//total net aces
$net_totalholeinonepts=$net_totalholeinone/$gamesfactor;
$nostats=$nostats+1;


//gross score
$avgscorepts=500/$avgscore;
$nostats=$nostats+1;

//net score
$net_avgscorepts=300/$net_avgscore;
$nostats=$nostats+1;

//gross birdie
$birdieavgpts=2*$birdieavg;
$nostats=$nostats+1;

//net birdie
$net_birdieavgpts=$net_birdieavg;
$nostats=$nostats+1;

//gross par
$paravgpts=$paravg;
$nostats=$nostats+1;

//net par						`
$net_paravgpts=$net_paravg/2;
$nostats=$nostats+1;

//gross parbreakers
$parbreakerspts=$parbreakers;
$nostats=$nostats+1;

//net parbreakers
$net_parbreakerspts=$net_parbreakers/10;
$nostats=$nostats+1;

//gross scrambling
$scramblingpts=$scrambling/10;
$nostats=$nostats+1;

//net scranbling
$net_scramblingpts=$net_scrambling/20;
$nostats=$nostats+1;

//calculate points
if ($nostats>0) {
$statpoints=$avgscorepts+net_avgscorepts+$puttavgpts+$girpctpts+$daccuracypts+$ddistancepts+$totaleaglespts+$net_totaleaglespts+$totaldoubleeaglespts+$net_totaldoubleeaglespts+$totalholeinonepts+$net_totalholeinonepts+$birdieavgpts+net_birdieavgpts+$paravgpts+net_paravgpts+$parbreakerspts+$net_parbreakerspts+scramblingpts+$net_scramblingpts/$nostats;
echo "<h3>Stats for $alluserid</h3>";
echo "<p>Gross Score:$avgscorepts<br>Netscore:$net_avgscorepts<br>Putts:$puttavgpts<br> Gir:$girpctpts<br> Fairway:$daccuracypts<br> Drive:$ddistancepts<br>
Eagles:$totaleaglepts<br>Net Eagles: $net_totaleaglespts<br>DoubleEagles:$totaldoubleeaglepts<br>Net DoubleEagles: $net_totaldoubleeaglespts<br>Aces:$totalholeinonepts<br>Net Aces: $net_totalholeinonepts<br>Gross Birdie:$birdieavgpts<br>Net Birdie:$net_birdieavgpts<br>
Gross Par:$paravgpts<br>Net Par:$net_paravgpts<br>Parbreakers:$parbreakerspts<br>Net Parbreakers:$net_parbreakerspts<br>
Scrambling:$scramblingpts<br>Net Scrambling:$net_scramblingpts<br> Stats:$nostats;";
}else {
$statpoints=0;
}

echo "<p>$alluserid has $statpoints points!";


//now calculate tournament points
//count how many tournaments
$notourneysql="Select * from games  
					where userid = '$alluserid' and tournament=1";

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

$tourneywins="0";
$tourney3="0";
$tourney5="0";	
$tourneybest=100;

if ($notourneyexist) {

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

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

if (($tourneyplace==4) || ($tourneyplace==3)) {
$tourney5=$tourney5+1;
}
} while ($notourneyrow=mysql_fetch_array($notourneyquery)); 



}

//caculate
$tournamentpoints=$tourneywins*3+$tourney3*2+$tourney5;

echo "<p>$alluserid has $tourneywins wins, $tourney3 top3s and $tourney5 top5s!<p>";
echo "<p>$alluserid has $tournamentpoints tournament points!<p>";


//not fair to add in tournaments for those never participated in tournament. I will leave it as an option
//$totaluserpoints=round($tournamentpoints+$statpoints,2);
$totaluserpoints=round($statpoints,2);

echo "$totaluserpoints<h3>$alluserid has total of $totaluserpoints points!</h3>";


//finally insert into total_points category


 $pointaddsql = "UPDATE ranking SET total_points = '$totaluserpoints' WHERE userid = '$alluserid'";
 $pointaddresult=mysql_query($pointaddsql);

//echo $pointaddsql;



} else {

echo "<p>No games exist for $alluserid!<p>";

}


} while ($alluserrow=mysql_fetch_array($alluserquery));



?>

<? showfooter(); ?>

Return current item: GolfstatsPHP