<?php

				include('database.php');
				DB_connexion(); 
				
				
				
				
				

				$sql = "SELECT * FROM parties ORDER by date asc"; 
				$results = mysql_query($sql);
				$nb_parties = mysql_num_rows($results);
							
				while($row = mysql_fetch_assoc($results))
				{
	
					$date_partie = $row['date'];
					$blanc = $row['w_name'];
					$noir = $row['b_name'];
					$resultat = $row['result'];
					
					if($resultat == 1)
					{
						$_score_blanc = 1;
						$_score_noir = 0;
					}
					if($resultat == 2)
					{
						$_score_blanc = 0;
						$_score_noir = 1;
					}
					if($resultat == 3)
					{
						$_score_blanc = 0.5;
						$_score_noir = 0.5;
					}
				
					$table_csv[0] = $date_partie;
					$table_csv[1] = $blanc;
					$table_csv[2] = $noir;
					$table_csv[3] = $_score_blanc;
					$table_csv[4] = $_score_noir;

					$table_fichier[] = $table_csv;
				}
	
				$nom_fichier = "aaaaaaasauvegarde.txt";
							
				$fp = fopen($nom_fichier, 'w'); 
				for ($i=0; $i < $nb_parties; $i++)
				{
					$str_comma_separated = implode(";", $table_fichier[$i]);
					fputs ($fp, $str_comma_separated);
					if($i != $nb_parties - 1)
					fputs($fp, "\n");
				}
						
				fclose($fp);

				echo "<pre>";
				print_r($table_fichier);
				
				
				
				/*
				$debut_mois = 12;
				$debut_jour = 15;
				$debut_annee = 2006;
				$fin_mois = 2;
				$fin_jour = 20;
				$fin_annee = 2007;

				$debut_date = mktime(0, 0, 0, $debut_mois, $debut_jour, $debut_annee);
				$fin_date = mktime(0, 0, 0, $fin_mois, $fin_jour, $fin_annee);

				for($i = $debut_date; $i <= $fin_date; $i+=86400)
				{
					echo date("l, F d Y.",$i)."<br />"
				}*/


?>