1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| <?php
$fusion = array(); // tableau vide
// traitement du 1er csv
$g1 = "gondrecourt/CLTP1.csv";
if(file_exists($g1)) {
$pg1 = fopen($g1, 'rb');
while (($ligne = fgetcsv($pg1, 1000, ",")) !== FALSE) {
$fusion[] = $ligne;
}
array_pop($fusion);
}
// traitement du 2ème csv
$m1 = "montrouge/CLTP1.csv";
if(file_exists($m1)) {
$pm1 = fopen($m1, 'rb');
while (($ligne = fgetcsv($pm1, 1000, ",")) !== FALSE) {
$fusion[] = $ligne;
}
array_pop($fusion);
}
// traitement du 3ème csv
$q1 = "quimper/CLTP1.csv";
if(file_exists($q1)) {
$pq1 = fopen($q1, 'rb');
while (($ligne = fgetcsv($pq1, 1000, ",")) !== FALSE) {
$fusion[] = $ligne;
}
array_pop($fusion);
}
// tri par score
function cmpclass($a, $b) {
if ($a[8] == $b[8]) {
return 0;
}
//inversion de la comparaison pour ordre décroissant
return ($a[8] > $b[8]) ? -1 : 1;
}
usort($fusion, "cmpclass");
//ajout du classement
$j = sizeof($fusion) ;
for ($i = 0; $i < $j; ++$i) {
$fusion[$i][0] = $i+1;
$fusion[$i][0] = ++$i+1;
}
array_pop($fusion);
// fusion nom et prénom
for ($i = 0; $i < $j; ++$i) {
$fusion[$i][1] = $fusion[$i][2]." ".$fusion[$i][3];
unset ($fusion[$i][2]);
unset ($fusion[$i][3]);
unset ($fusion[$i][7]);
}
// lecture en table html de la fusion des 3 csv
echo '<table>'; //début du tableau html
echo "<colgroup></colgroup><colgroup align=left></colgroup><colgroup align=left></colgroup><colgroup></colgroup><colgroup></colgroup><colgroup></colgroup><colgroup align=right></colgroup>";
echo '<tr><th></th><th>nom</th><th>cat</th><th>série</th><th>club</th><th>cumul</th></tr>';
foreach($fusion as $ligne) {
echo '<tr>'; //début de la ligne
foreach ($ligne as $i => $elt) {
echo '<td>'.$elt.'</td>'; // une cas de la ligne
}
echo '</tr>'; //fin de la ligne
}
echo '</table>'; //fin du tableau html
//export csv
$fp = fopen('csv/cumul1.csv', 'w');
foreach ($fusion as $fields) {
fputcsv($fp, $fields, ';');
}
fclose($fp);
?> |
Partager