<?php

							include('database.php');

							DB_connexion(); 



							$donnees = array();

							$donnees[0] = "tttttt";

							$donnees[1] = "XXXXXXXX";

							$donnees[2] = "YYYYYYYY";

							$donnees[3] = "1";

							$donnees[4] = "0";

							print_r($donnees);

							

							$sql = "SELECT * FROM parties ORDER by date asc"; 

							$results = mysql_query($sql);

							$nb_parties = mysql_num_rows($results);

							

							while($row = mysql_fetch_assoc($results))

							{

								$blanc = $row['w_name'];

								$noir = $row['b_name'];

								$date = $row['date'];

								$resultat = $row['result'];

								$date_partie = date('d/m/Y', $date);

					

								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 = "sauvegarde_insertion.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);

							

							$id_position = 10;

							

							$tab1 = array();

							$tab2 = array();

							

							$fp = fopen($nom_fichier, 'w'); 

							for ($i=0; $i <= $id_position; $i++)

							{

								$tab1[] = $table_fichier[$i];

								

									

							}

							

							$table[] = $donnees;

							

							for ($i=$id_position+1 ; $i < $nb_parties; $i++)

							{

								$tab2[] = $table_fichier[$i];

								

									

							}

						

							echo "<pre>";

							//print_r($tab1);

							//print_r($tab2);

						

							$tab_global = array_merge($tab1,$table,$tab2);

							print_r($tab_global);

?>

