<?php

			session_start();
			include('database.php');
			DB_connexion(); 
			error_reporting( 0 );

			$sql = "SELECT * FROM classement"; 
			$results = mysql_query($sql);
			$nb = mysql_num_rows($results);
			
			$liste_joueur = array();
			
			while($row = mysql_fetch_assoc($results))
			{
				$liste_joueur[] = $row['joueur'];
			}
			
			echo "<pre>";
			print_r($liste_joueur);
			
			echo "**********************************";
			echo "<br>";
			
			$date = date("d-m-Y");
			list($jour, $mois, $annee) = explode('-', $date);
			$timestamp = mktime (0, 0, 0, $mois, $jour, $annee);
			echo "Timestamp du jour: " .$timestamp;

			echo "<br>";
						
			for ($i=0; $i < $nb ; $i++) 
			{
				$joueur = $liste_joueur[$i];
			
				$sql = "SELECT * FROM parties WHERE w_name = '$joueur' OR b_name = '$joueur' ORDER by date"; //  desc LIMIT 20";
				$results = mysql_query($sql);
				$nb_parties = mysql_num_rows($results);
				echo $nb_parties;
				echo "<br>";
					
				$tmp = array();
			
				while($row = mysql_fetch_assoc($results))
				{
					$tmp[] = $row['date'];
				}
			
				$store = array();
				$store[0] = $joueur;
				$store[1] = max($tmp);
				$store[2]  = date('d/m/Y',  max($tmp));
				$store[3] =  ceil( ( $timestamp - max($tmp) ) / 86400);
				$store[4]  = $nb_parties;
				
				
				$tab_classement[] = $store;
			}
			
			echo "<br>";
			echo "<pre>";
			print_r($tab_classement);
			
			//86400  1508968800
			
			$ttt = 1509055200 - 1508968800;
			
			$second_par_jour = 60*60*24;
			
			echo $ttt;
			mysql_close();
			
		    //$nb_jour = ($timestamp - 1450393200) / 86400;
			//
			//echo "<br>";
			//echo $nb_jour;
?>