Des erreurs sur l'affiche
Posté : 12 mars 2013, 03:48
Bonjour à toutes et tous,
Impossible de résoudre mon problème depuis quatre jours. En effet, j'ai l'erreur suivante quand je lance mon programme
Notice: Undefined offset: 1 in C:\wamp\www\Test\Chapitre_3\vieworders2.php on line 46
Voici le fichier entier:
<?php
// Création d’un nom abrégé de variable
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
?>
<html>
<head>
<title>Le garage de Bob - Commandes clients</title>
</head>
<body>
<h1>Le garage de Bob</h1>
<h2>Commandes clients</h2>
<?php
// Lecture du fichier complet.
// Chaque commande devient un élément du tableau
$commandes = file("$DOCUMENT_ROOT/dossier_source/orders.txt");
// Compte le nombre de commandes dans le tableau
$nbre_de_cdes = count($commandes);
if ($nbre_de_cdes == 0) {
echo "<p><strong>Aucune commande en attente.
Réessayez plus tard.</strong></p>";
}
echo "<table border=\"1\">\n";
echo "<tr><th bgcolor=\"#CCCCFF\">Date commande</th>
<th bgcolor=\"#CCCCFF\">Pneus</th>
<th bgcolor=\"#CCCCFF\">Huiles</th>
<th bgcolor=\"#CCCCFF\">Bougies</th>
<th bgcolor=\"#CCCCFF\">Total</th>
<th bgcolor=\"#CCCCFF\">Adresse</th>
<tr>";
for ($i = 0; $i < $nbre_de_cdes; $i++) {
// Découpage de chaque ligne
$ligne = explode("\t", $commandes[$i]);
// On ne conserve que le nombre d’articles commandés
$ligne[1] = intval($ligne[1]);
$ligne[2] = intval($ligne[2]);
$ligne[3] = intval($ligne[3]);
// Affiche chaque commande
echo "<tr>
<td>".$ligne[0]."</td>
<td align=\"right\">".$ligne[1]."</td>
<td align=\"right\">".$ligne[2]."</td>
<td align=\"right\">".$ligne[3]."</td>
<td align=\"right\">".$ligne[4]."</td>
<td>".$ligne[5]."</td>
</tr>";
}
echo "</table>";
?>
</body>
</html>
Merci de votre aide
Impossible de résoudre mon problème depuis quatre jours. En effet, j'ai l'erreur suivante quand je lance mon programme
Notice: Undefined offset: 1 in C:\wamp\www\Test\Chapitre_3\vieworders2.php on line 46
Voici le fichier entier:
<?php
// Création d’un nom abrégé de variable
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
?>
<html>
<head>
<title>Le garage de Bob - Commandes clients</title>
</head>
<body>
<h1>Le garage de Bob</h1>
<h2>Commandes clients</h2>
<?php
// Lecture du fichier complet.
// Chaque commande devient un élément du tableau
$commandes = file("$DOCUMENT_ROOT/dossier_source/orders.txt");
// Compte le nombre de commandes dans le tableau
$nbre_de_cdes = count($commandes);
if ($nbre_de_cdes == 0) {
echo "<p><strong>Aucune commande en attente.
Réessayez plus tard.</strong></p>";
}
echo "<table border=\"1\">\n";
echo "<tr><th bgcolor=\"#CCCCFF\">Date commande</th>
<th bgcolor=\"#CCCCFF\">Pneus</th>
<th bgcolor=\"#CCCCFF\">Huiles</th>
<th bgcolor=\"#CCCCFF\">Bougies</th>
<th bgcolor=\"#CCCCFF\">Total</th>
<th bgcolor=\"#CCCCFF\">Adresse</th>
<tr>";
for ($i = 0; $i < $nbre_de_cdes; $i++) {
// Découpage de chaque ligne
$ligne = explode("\t", $commandes[$i]);
// On ne conserve que le nombre d’articles commandés
$ligne[1] = intval($ligne[1]);
$ligne[2] = intval($ligne[2]);
$ligne[3] = intval($ligne[3]);
// Affiche chaque commande
echo "<tr>
<td>".$ligne[0]."</td>
<td align=\"right\">".$ligne[1]."</td>
<td align=\"right\">".$ligne[2]."</td>
<td align=\"right\">".$ligne[3]."</td>
<td align=\"right\">".$ligne[4]."</td>
<td>".$ligne[5]."</td>
</tr>";
}
echo "</table>";
?>
</body>
</html>
Merci de votre aide