<?php

function elo_glissant($playerID, $plage)
{	

					$sql = "SELECT * FROM parties WHERE w_playerid = '$playerID' OR b_playerid = '$playerID' ORDER by date desc LIMIT 20";
					//$sql = "SELECT * FROM parties WHERE w_playerid = '$playerID' OR b_playerid = '$playerID' ORDER by date desc LIMIT " .$plage;
					//echo $sql;
					//echo "<br>";
					
					$retid = mysql_query($sql);

					$partie_win = 0;
					$partie_losses = 0;
					$partie_nulle = 0;

					while ($row = mysql_fetch_array($retid)) 
					{	 
						$white = $row["w_playerID"]; 
						$black = $row["b_playerID"];
						$result=$row["result"];

						if($white==$playerID)
						{
							if ($result==1) 
							{
								$partie_win = $partie_win + 1;		
							}

							if($result==2)
							{
								$partie_losses = $partie_losses + 1;		
							}

							if ($result==3)
							{
								$partie_nulle = $partie_nulle + 1;		
							}
						}

						if ($black==$playerID)
						{

							if($result==1)
							{
								$partie_losses = $partie_losses + 1;		
							}

							if ($result==2)
							{
								$partie_win = $partie_win + 1;		
							}

							if ($result==3)
							{
								$partie_nulle = $partie_nulle + 1;		
							}
						} 
					} 
	
	
					//echo $partie_win ."  " .$partie_losses ."  " . $partie_nulle;
					//echo "<br>";	
					
					$gcount = 20;

					$efficacite = ($partie_win + 0.5 * $partie_nulle) / $gcount;

					$efficacite = $efficacite * 100;

					$efficacite = round($efficacite, 2);

					//$efficacite = $efficacite ." %";

					

					return($efficacite);

					

/*				

				$winp=round(($partie_win/$gcount)*100,2);

				$lossp=round(($partie_losses/$gcount)*100,2);

				$drawp=round(($partie_nulle/$gcount)*100,2);



				echo $partie_win ."  " .$winp;

				echo "<br>";

				echo $partie_losses ."  " .$lossp; 

				echo "<br>";

				echo $partie_nulle ."  " .$drawp;

				echo "<br>";

				echo "Efficacite -> " .$efficacite;

				echo "<br>";

*/				

}	





?>



