Notice: Undefined offset: 11

Résolu
F2C Messages postés 51 Date d'inscription   Statut Membre Dernière intervention   -  
F2C Messages postés 51 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

J'ai une erreur dans mon code PHP suivant:

<table class="border">
<thead>
<tr>
<th>ODM</th>
<th>SECTEUR</th>
<th>TA</th>
<th>URGENCE</th>
<th>CLOT</th>
<?php
$sql0=$bdd->query("SELECT DISTINCT Matricule FROM pointages WHERE Date_Pointage = '$date'");
$row0=$sql0->fetchAll();
$j = 0;
$table1 = array();
$table=array();
foreach($row0 as $numero0)
{
$matricule=$numero0['Matricule'];
$table1[$j] = $matricule;
$sql5=$bdd->query("SELECT Nom, Prenom FROM matricules WHERE Matricule ='$matricule'");
$row5=$sql5->fetchAll();
$j++;
foreach($row5 as $mat)
{
?>
<th> <div><?php echo $mat['Nom'].' '.$mat['Prenom'];?></div></th>
<?php
}
}
?>
<th> TOTAL GENRAL</th>
</tr>
</thead>
<tbody>
<tr>
<?php
$i=0;
$sql1=$bdd->query("SELECT DISTINCT Num_OS_Client FROM pointages_fact WHERE Num_Pointage IN (SELECT Numero FROM pointages WHERE Date_Pointage ='$date')");
$row1=$sql1->fetchALL();
$table2=array();
foreach($row1 as $numero1)
{
$ordre=$numero1['Num_OS_Client'];
$sql2=$bdd->query("SELECT Ordre_Client, Libelle, Secteur, Metier, Urgence, Date_Clot_Tech FROM ordres_mic WHERE Ordre_Client='$ordre'");
$row2=$sql2->fetchAll();
foreach($row2 as $donnees)
{
?>

<?php
$a = $donnees['Ordre_Client'];
$b = $donnees['Libelle'];
$ab = $a.' - '.$b;
$c = $donnees['Secteur'];
$d = $donnees['Metier'];
$e = $donnees['Urgence'];

if($donnees['Date_Clot_Tech'] == '0000-00-00')
{
$f = "NON";
$table[$i]= $ab.'||'.$c.'||'.$d.'||'.$e.'||'.$f;
}
else
{
$f = "OUI";
$table[$i]= $ab.'||'.$c.'||'.$d.'||'.$e.'||'.$f;
}
$i++;
}
}

for($z =0; $z<=$i; $z++)
{
$ich =$table[$z];
$explo = explode('||', $ich);
$odm = $explo[0];
$secteur = $explo[1];
$metier = $explo[2];
$urgence = $explo[3];
$clot = $explo[4];
?>
<td><?php echo $odm;?></td>
<td><?php echo $secteur;?></td>
<td><?php echo $metier;?></td>
<td><?php echo $urgence;?></td>
<td><?php echo $clot;?></td>
<?php
$lol = explode(' - ', $odm);
$lo = $lol[0];
$sum=0;
$y=0;
while($y<=$j)
{
$mat = $table1[$y];
$sql3=$bdd->query("SELECT Fact_H, Num_OS_Client FROM pointages_fact WHERE Num_Pointage IN (Select Numero FROM pointages WHERE Date_Pointage='$date' AND Matricule='$mat')");
$row3=$sql3->fetchAll();
foreach($row3 as $numero3)
{
$heure=$numero3['Fact_H'];
$sum = $sum + $heure;
$os=$numero3['Num_OS_Client'];
$sql5=$bdd->query("SELECT Matricule FROM pointages WHERE (Numero IN(Select Num_Pointage FROM pointages_fact WHERE Num_OS_Client = '$lo')) AND Date_Pointage='$date'");
$row5=$sql5->fetch();
$matricule2=$row5['Matricule'];
if($mat == $matricule2)
{
?>
<td><?phpecho $heure;?></td>
<?php
}
else
{
?>
<td> </td>
<?php
}
}
$y++;
}
?>
<td><?php echo $sum;?></td>
<?php
}
?>
</tr>
</tbody>
</table>


Plus précisement à cette ligne :
$mat = $table1[$y];

quand j'execute ça m'affiche une erreur(cf titre du message) ;
Est ce que quelqu'un aurait une solution à mon problème svp?


1 réponse

CptRomaiin Messages postés 315 Date d'inscription   Statut Membre Dernière intervention   58
 
Salut,

Alors si j'ai bien lu ton code et si je me goure pas, lorsque tu fais le premier foreach, ta variable $j est incrémentée une fois supplémentaire lors de la dernière boucle. Donc cette variable est égale à ton nombre d'enregistrement + 1.

Pour résoudre ton problème, tu peux remplacer la ligne
while($y<=$j) 
par
while($y<$j)
ou
while($y<=$j-1) 
.

Dis moi si ça fonctionne.
0
F2C Messages postés 51 Date d'inscription   Statut Membre Dernière intervention  
 
Merci ça fonctionne très bien
0