Mon index.php contient 3 includes :
- 1 pour la base (la connexion fonctionne puisque je peux afficher mes magasins si je ne mets pas de règles restrictives à ma requête)
- 1 pour la récupération des données du fichier excel dans un tableau php : $montab[$i][$j] (je récupère aussi le nombre total de ligne et de colonne du fichier excel)
- 1 pour le traitement et comparaison avec les données de ma base
Voici le code du dernier qui nous intéresse :
Code : Tout sélectionner
<?php
// LES FONCTIONS
// Fonction de vérification si le magasin est dans la base
function existmag($nommag){
$existmonmag = 0;
//$query_existmag = "SELECT * FROM `mp_magasin` WHERE titremag=`$nommag` ";
//$query_existmag = "SELECT * FROM `mp_magasin` WHERE MATCH(titremag) AGAINST '$nommag' ";
$query_existmag = "SELECT * FROM `mp_magasin` WHERE MATCH(titremag) AGAINST ('$nommag')";
$mysql_existmag = mysql_query($query_existmag);
echo $query_existmag.'<br />';
if (!$mysql_existmag) {
echo "Impossible d'exécuter la requête ($query_existmag) dans la base : " . mysql_error();
}
else
{
if (mysql_num_rows($mysql_existmag) == 0) {
echo "<br /><strong>Aucune ligne trouvée, rien à afficher.</strong><br />";
}
while ($rowmagasin=mysql_fetch_assoc($mysql_existmag) ) {
//print_r ($rowmagasin).'<br />';
//$rowmagasin['titremag'] = str_replace(" ","",$rowmagasin['titremag']);
if (strcasecmp($rowmagasin['titremag'], $nommag) == 0) {
$existmonmag = $rowmagasin['idmag'];
//echo 'oui c est égal : '.$rowmagasin['idmag'].'-'.$rowmagasin['titremag'];
//echo ' >>><strong> '.$existmonmag.'</strong><br />';
}
}
}
return $existmonmag;
}
// FIN DES FONCTIONS
?>
<?php
/* Insertion du fichier excel dans la base de données */
echo "<i>Données insérées dans la base</i> <br />";
/* Récupération du nombre total de colonne et de ligne du fichier excel */
$max_cols = $col-1;
$max_rows = $row-1;
echo $max_cols." colonnes et ".$max_rows." lignes, et ";
echo $max_cols-3 ." magasins<br /><br />";
$i=1 ;// $i = nombre de ligne
while($i<=$max_rows)
{
$j=1;// $j = nombre de colonne
while($j<=$max_cols)
{
// 1ere ligne = liste des magasins
if($i==1)
{
//for($j=4; $j<=$max_cols; $j++)
//{
//echo '// '.$montab[$i][$j].' - ';
//
if($j>=4){
//$montab[$i][$j] = str_replace("\n"," ",$montab[$i][$j]);
//$montab[$i][$j] = str_replace(" "," ",$montab[$i][$j]);
$montabtrimmed[$i][$j] = trim($montab[$i][$j], "\t.");
$montabtrimmed[$i][$j] = trim($montab[$i][$j], "\n.");
$montabtrimmed[$i][$j] = trim($montab[$i][$j], "\r.");
$montabtrimmed[$i][$j] = trim($montab[$i][$j], "Hdle");
$montabtrimmed[$i][$j] = trim($montab[$i][$j], "\x0B");
$montabtrimmed[$i][$j] = trim($montab[$i][$j], "\x00..\x1F");
// Recherche si magasin du fichier excel existe dans la base
$existmonmag = existmag($montabtrimmed[$i][$j]);
// Cas où le magasin du fichier excel existe dans la base
if($existmonmag != 0)
{
//echo $existmonmag;
}
// Cas où le magasin du fichier excel N'existe PAS dans la base
else{
// Cas insertion du magasin du fichier excel dans la base
// Encore à faire ...
}
$tabidmag[$j] = $existmonmag;
echo "pp".$tabidmag[$j]."pp<br /><br />";
}
//}
//echo $montab[$i][4].'-';
}
// Fin de première ligne
$j++;
}
//echo "</tr>";
$i++;
}
//echo "</table>";
?>