Voici un exemple de mon csv que je reçois:
Début : 02 novembre 2017;
Fin : 12 novembre 2017;
Gestantes;11/11/2017;10/11/2017;09/11/2017;08/11/2017;07/11/2017;06/11/2017;05/11/2017;04/11/2017;03/11/2017;02/11/2017;
23h à 24h;5;11;1;34;1;28;8;6;0;0;
22h à 23h;14;1;0;57;23;0;12;0;9;5;
21h à 22h;21;16;15;54;23;23;32;22;23;40;
20h à 21h;64;46;34;58;57;45;44;60;38;55;
19h à 20h;82;62;54;74;61;50;61;52;56;55;
18h à 19h;33;65;49;63;69;71;78;53;84;58;
17h à 18h;58;61;77;70;80;74;83;70;53;106;
16h à 17h;51;68;62;102;79;65;41;75;76;97;
15h à 16h;49;82;77;76;82;90;56;78;76;65;
14h à 15h;65;65;72;69;73;103;61;60;63;62;
13h à 14h;64;60;80;52;58;67;68;76;71;61;
12h à 13h;69;76;42;40;79;72;74;53;52;84;
11h à 12h;54;58;44;49;96;59;49;59;66;64;
10h à 11h;62;53;78;48;53;53;53;61;79;57;
9h à 10h;45;46;71;57;47;56;53;46;58;50;
8h à 9h;43;41;57;45;42;47;54;36;38;45;
7h à 8h;30;21;16;1;10;28;9;14;33;10;
6h à 7h;8;1;1;14;6;5;9;15;7;4;
5h à 6h;21;5;8;0;3;0;0;2;0;0;
4h à 5h;0;6;1;1;1;1;0;1;3;1;
3h à 4h;2;1;0;7;0;0;1;0;0;0;
2h à 3h;4;4;1;7;0;3;0;0;0;0;
1h à 2h;1;19;1;1;1;4;11;0;4;5;
0h à 1h;11;16;0;1;12;5;21;7;2;1;
Total:;856;884;841;980;956;949;878;846;891;925;
Nombre porcs:;0;0;0;0;0;0;0;0;0;0;
Total Gestantes:;9006;
PS1;11/11/2017;10/11/2017;09/11/2017;08/11/2017;07/11/2017;06/11/2017;05/11/2017;04/11/2017;03/11/2017;02/11/2017;
23h à 24h;13;11;15;6;7;9;8;16;15;0;
22h à 23h;16;15;14;16;10;13;15;4;10;0;
21h à 22h;19;17;21;20;14;9;13;17;10;0;
20h à 21h;15;22;10;21;16;23;8;14;16;0;
19h à 20h;34;24;17;9;23;15;22;17;13;0;
18h à 19h;51;39;43;35;18;20;14;18;13;0;
17h à 18h;86;88;73;58;68;61;59;54;48;0;
16h à 17h;84;73;78;73;67;61;67;59;46;0;
15h à 16h;79;85;71;74;72;69;67;62;55;0;
14h à 15h;83;76;70;75;62;65;64;53;37;0;
13h à 14h;69;61;72;67;72;67;48;55;38;0;
12h à 13h;76;73;75;62;62;55;53;40;31;0;
11h à 12h;76;76;63;67;61;61;56;41;52;0;
10h à 11h;73;66;66;63;64;67;52;49;49;0;
9h à 10h;84;79;73;67;74;57;50;40;27;0;
8h à 9h;34;31;24;28;23;22;19;18;4;0;
7h à 8h;3;2;3;2;3;1;1;3;0;0;
6h à 7h;1;1;1;2;0;0;1;1;0;0;
5h à 6h;1;2;1;1;1;0;0;3;0;0;
4h à 5h;4;1;1;0;1;1;1;3;0;0;
3h à 4h;4;4;2;1;0;0;4;4;0;0;
2h à 3h;6;3;4;4;2;2;5;7;0;0;
1h à 2h;9;9;4;3;4;7;5;11;0;0;
0h à 1h;13;6;8;8;5;4;10;7;0;0;
Total:;933;864;809;762;729;689;642;596;464;0;
Voici ma BDD:
Code : Tout sélectionner
<?xml version="1.0" encoding="UTF-8"?>
<!-- - phpMyAdmin XML Dump - version 4.7.4 - https://www.phpmyadmin.net - - Hôte : 127.0.0.1:3306 - Généré le : mar. 14 nov. 2017 à 09:55 - Version du serveur : 5.7.19 - Version de PHP : 5.6.31 -->
-<pma_xml_export xmlns:pma="https://www.phpmyadmin.net/some_doc_url/" version="1.0">
<!-- - Structure schemas -->
-<pma:structure_schemas>
-<pma:database charset="latin1" collation="latin1_swedish_ci" name="gestion_compteur_eau">
<pma:table name="releve"> CREATE TABLE `releve` ( `id` int(11) NOT NULL AUTO_INCREMENT, `type` varchar(50) DEFAULT NULL, `date` date NOT NULL, `heure_23` int(11) NOT NULL, `heure_22` int(11) NOT NULL, `heure_21` int(11) NOT NULL, `heure_20` int(11) NOT NULL, `heure_19` int(11) NOT NULL, `heure_18` int(11) NOT NULL, `heure_17` int(11) NOT NULL, `heure_16` int(11) NOT NULL, `heure_15` int(11) NOT NULL, `heure_14` int(11) NOT NULL, `heure_13` int(11) NOT NULL, `heure_12` int(11) NOT NULL, `heure_11` int(11) NOT NULL, `heure_10` int(11) NOT NULL, `heure_09` int(11) NOT NULL, `heure_08` int(11) NOT NULL, `heure_07` int(11) NOT NULL, `heure_06` int(11) NOT NULL, `heure_05` int(11) NOT NULL, `heure_04` int(11) NOT NULL, `heure_03` int(11) NOT NULL, `heure_02` int(11) NOT NULL, `heure_01` int(11) NOT NULL, `heure_00` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; </pma:table>
</pma:database>
</pma:structure_schemas>
<!-- - Base de données : 'gestion_compteur_eau' -->
-<database name="gestion_compteur_eau">
<!-- Table releve -->
</database>
</pma_xml_export>
Mon but est donc de faire une recherche dans le CSV dès qu'il trouve Gestantes il crée un nouvel enregistrement en mettant gestantes dans le type de la BDD, la première date dans date, ensuite toutes les données des différentes heures se trouvant en dessous de la date correspondante. Ensuite on prend la deuxième date sur la même ligne et on refait pareil, on crée un nouvel enregistrement et ce jusqu'à la dernière date.
Ensuite on passe au deuxième tableau.