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
| <?php
$row = 1;
$handle = fopen("upload/groupe.csv", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
list($champ1, $champ2, $champ3) = explode(';',$data[$c]);
//test existence des données :
$test=mysql_query("SELECT * from tab_groupe WHERE sigle='".$champ1."' AND date_fondation='".$champ2."' AND capital='".$champ3."'") or die(mysql_error());
$test2=mysql_fetch_array($test);
//Si les données sont inexistantes dans la BDD, insertion :
if($test2 == '0') {
$req=mysql_query("INSERT INTO tab_groupe (id_groupe, sigle, date_fondation, capital) VALUE ('', '$champ1', '$champ2', '$champ3')") or die(mysql_error());
}
if($test2 != '0') {
}
}}
fclose($handle);
?> |
Partager