IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Notice: Undefined offset


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Femme Profil pro
    Chargé de référencement
    Inscrit en
    Mars 2018
    Messages
    38
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Chargé de référencement
    Secteur : Bâtiment Travaux Publics

    Informations forums :
    Inscription : Mars 2018
    Messages : 38
    Par défaut Notice: Undefined offset
    Bonjour, j'ai un petit problème je construis un site qui affiche la liste des années disponibles
    pour les films listés.
    Quand l’utilisateur clique sur une année, les films liés sont affichés
    Et quand l’utilisateur sélectionne une date, la liste des films liés est affichée
    avec leur description

    1ere page :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    <?php
    $annees = array ( '2010', '2011', '2012', '2013', '2014');
    ?>
     
    <ul>
    <?php foreach ($annees as $annee) { ?>
     
    <li><a href="film.php?annee=<?php echo $annee ?>"><?php echo $annee ?></a></li>
     
    <?php } ?>
    </ul>
    Ici tout s'affiche comme je veux.

    2eme page :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    $films = [
    [2010, [['Inception','descriptio 001'], ['Skyline','descriptio 002'], ['Monsters','descriptio 003'], ['Predators','descriptio 004'], ['Repo Men','descriptio 005']]],
    [2011, [['Eva','descriptio 001'], ['Gantz','descriptio 002'], ['Hell','descriptio 003'], ['Super 8','descriptio 004'], ['Time Out','descriptio 005']]],
    [2012, [['The End','descriptio 001'], ['Looper','descriptio 001'], ['Antiviral','descriptio 001'], ['Battleship','descriptio 001'], ['Lock Out','descriptio 001']]],
    [2013, [['Dreed','descriptio 001'], ['Gravity','descriptio 001'], ['Oblivion','descriptio 001'], ['Pacific Rim','descriptio 001'], ['Riddick','descriptio 001']]],
    [2014, [['Echo','descriptio 001'], ['The Rover','descriptio 001'], ['Lucy','descriptio 001'], ['Godzilla','descriptio 001'], ['The Giver','descriptio 001']]]
    ];
     
    foreach ($films as $cle => $value) {
    if ($value[0] == $_GET['annee'])
    { ?>
    <ul>
    <?php foreach ($value[1] as $film){ ?>
    <li>
    <?php echo $film[0]; ?>
    <p><?php echo $film[1]; ?></p>
     
    </li>
    <?php } ?>
    </ul>
    <?php
    }
    }
    ?>
    Ici il y a une erreur
    Notice: Undefined offset: 5 in C:\wamp64\www\film\film.php on line 12
    J'ai essayé de modifier les valeurs mais ça ne marche pas je n'arrive pas à afficher les films avec leurs descriptif.

    Merci d'avance pour votre aide

  2. #2
    Membre confirmé
    Homme Profil pro
    Autre
    Inscrit en
    Août 2017
    Messages
    63
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Autre

    Informations forums :
    Inscription : Août 2017
    Messages : 63
    Par défaut
    Salut à toi
    edite ton message et utilise le bouton code pour que le code soit plus visible

    déjà ça m'a sauté aux yeux
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    $films = [
    [2010, [['Inception','descriptio 001'], ['Skyline','descriptio 002'], ['Monsters','descriptio 003'], ['Predators','descriptio 004'], ['Repo Men','descriptio 005']]],
    [2011, [['Eva','descriptio 001'], ['Gantz','descriptio 002'], ['Hell','descriptio 003'], ['Super 8','descriptio 004'], ['Time Out','descriptio 005']]],
    [2012, [['The End','descriptio 001'], ['Looper','descriptio 001'], ['Antiviral','descriptio 001'], ['Battleship','descriptio 001'], ['Lock Out','descriptio 001']]],
    [2013, [['Dreed','descriptio 001'], ['Gravity','descriptio 001'], ['Oblivion','descriptio 001'], ['Pacific Rim','descriptio 001'], ['Riddick','descriptio 001']]],
    [2014, [['Echo','descriptio 001'], ['The Rover','descriptio 001'], ['Lucy','descriptio 001'], ['Godzilla','descriptio 001'], ['The Giver','descriptio 001']]]
    ];
    remplace par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    $films = array(
        '2010' => array(
            array('Inception','descriptio 001'),
            array('Skyline','descriptio 002'), 
            array('Monsters','descriptio 003'), 
            array('Predators','descriptio 004'), 
            array('Repo Men','descriptio 005')
        ),
        '2011' => array(
             array('Eva','descriptio 001'), 
             array('Gantz','descriptio 002'), 
             array('Hell','descriptio 003'), 
             array('Super 8','descriptio 004'), 
             array('Time Out','descriptio 005')
        ),
        '2012' => array(
             array('The End','descriptio 001'), 
             array('Looper','descriptio 001'), 
             array('Antiviral','descriptio 001'), 
             array('Battleship','descriptio 001'), 
             array('Lock Out','descriptio 001')
        ),
        '2013' => array(
             array('Dreed','descriptio 001'), 
             array('Gravity','descriptio 001'), 
             array('Oblivion','descriptio 001'), 
             array('Pacific Rim','descriptio 001'), 
             array('Riddick','descriptio 001')
        ),
        '2014' => array(
            array('Echo','descriptio 001'), 
            array('The Rover','descriptio 001'), 
            array('Lucy','descriptio 001'), 
            array('Godzilla','descriptio 001'), 
            array('The Giver','descriptio 001')
        )
    );

  3. #3
    Membre averti
    Femme Profil pro
    Chargé de référencement
    Inscrit en
    Mars 2018
    Messages
    38
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Chargé de référencement
    Secteur : Bâtiment Travaux Publics

    Informations forums :
    Inscription : Mars 2018
    Messages : 38
    Par défaut
    D'accord et j'ai remplacer le code mais il me marque toujours la même erreur et maintenant à la premiere page j'ai les liens des années qui s'affiche mais quand je clique dessus je n'ai plus les films avec leur descriptions.

  4. #4
    Membre confirmé
    Homme Profil pro
    Autre
    Inscrit en
    Août 2017
    Messages
    63
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Autre

    Informations forums :
    Inscription : Août 2017
    Messages : 63
    Par défaut
    Modifie ton premier message. Je ne vois rien sur mon téléphone. Utilise les balises

  5. #5
    Membre averti
    Femme Profil pro
    Chargé de référencement
    Inscrit en
    Mars 2018
    Messages
    38
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Chargé de référencement
    Secteur : Bâtiment Travaux Publics

    Informations forums :
    Inscription : Mars 2018
    Messages : 38
    Par défaut
    Citation Envoyé par colem Voir le message
    Modifie ton premier message. Je ne vois rien sur mon téléphone. Utilise les balises

    1ere page

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
     
    <?php
    $annees = array ( '2010', '2011', '2012', '2013', '2014');
    ?>
     
    <ul>
    <?php foreach ($annees as $annee) { ?>
     
    <li><a href="film.php?annee=<?php echo $annee ?>"><?php echo $annee ?></a></li>
     
    <?php } ?>
    </ul>
    2e page

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <?php
     
    $films = array(
        '2010' => array(
            array('Inception','descriptio 001'),
            array('Skyline','descriptio 002'), 
            array('Monsters','descriptio 003'), 
            array('Predators','descriptio 004'), 
            array('Repo Men','descriptio 005')
        ),
        '2011' => array(
             array('Eva','descriptio 001'), 
             array('Gantz','descriptio 002'), 
             array('Hell','descriptio 003'), 
             array('Super 8','descriptio 004'), 
             array('Time Out','descriptio 005')
        ),
        '2012' => array(
             array('The End','descriptio 001'), 
             array('Looper','descriptio 001'), 
             array('Antiviral','descriptio 001'), 
             array('Battleship','descriptio 001'), 
             array('Lock Out','descriptio 001')
        ),
        '2013' => array(
             array('Dreed','descriptio 001'), 
             array('Gravity','descriptio 001'), 
             array('Oblivion','descriptio 001'), 
             array('Pacific Rim','descriptio 001'), 
             array('Riddick','descriptio 001')
        ),
        '2014' => array(
            array('Echo','descriptio 001'), 
            array('The Rover','descriptio 001'), 
            array('Lucy','descriptio 001'), 
            array('Godzilla','descriptio 001'), 
            array('The Giver','descriptio 001')
        )
    );
     
    foreach ($films as $cle => $value) {
    if ($value[0] == $_GET['annee'])
    { ?>
    <ul>
    <?php foreach ($value[1] as $film){ ?>
    <li>
    <?php echo $film[0]; ?>
    <p><?php echo $film[1]; ?></p>
     
    </li>
    <?php } ?>
    </ul>
    <?php
    }
    }
    ?>

  6. #6
    Membre confirmé
    Homme Profil pro
    Autre
    Inscrit en
    Août 2017
    Messages
    63
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Autre

    Informations forums :
    Inscription : Août 2017
    Messages : 63
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <?php
    $annees = array ( '2010', '2011', '2012', '2013', '2014');
     
    echo "<ul>\n";
    foreach ($annees as $annee) {
        echo "<li><a href=\"film.php?annee=$annee\">$annee</a></li>\n";
    }
    echo "</ul>\n";
     
    ?>
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <?php
     
    $films = array(
        '2010' => array(
            array('Inception','descriptio 001'),
            array('Skyline','descriptio 002'), 
            array('Monsters','descriptio 003'), 
            array('Predators','descriptio 004'), 
            array('Repo Men','descriptio 005')
        ),
        '2011' => array(
             array('Eva','descriptio 001'), 
             array('Gantz','descriptio 002'), 
             array('Hell','descriptio 003'), 
             array('Super 8','descriptio 004'), 
             array('Time Out','descriptio 005')
        ),
        '2012' => array(
             array('The End','descriptio 001'), 
             array('Looper','descriptio 001'), 
             array('Antiviral','descriptio 001'), 
             array('Battleship','descriptio 001'), 
             array('Lock Out','descriptio 001')
        ),
        '2013' => array(
             array('Dreed','descriptio 001'), 
             array('Gravity','descriptio 001'), 
             array('Oblivion','descriptio 001'), 
             array('Pacific Rim','descriptio 001'), 
             array('Riddick','descriptio 001')
        ),
        '2014' => array(
            array('Echo','descriptio 001'), 
            array('The Rover','descriptio 001'), 
            array('Lucy','descriptio 001'), 
            array('Godzilla','descriptio 001'), 
            array('The Giver','descriptio 001')
        )
    );
     
    foreach ($films as $cle => $value) {
       if ($cle == $_GET['annee']) { 
            echo "<ul>\n";
            foreach ($value as $film) {
                echo "<li>\n";
                echo $film[0]."\n";
                echo "<p>$film[1]</p>\n";
                echo "</li>\n";
           }
           echo "</ul>\n";
        }
    }
    ?>
    essaye ça

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [MySQL] Notice: Undefined offset
    Par gaetanc15 dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 30/04/2009, 16h16
  2. [Tableaux] Notice: Undefined offset
    Par KOogar dans le forum Langage
    Réponses: 16
    Dernier message: 02/02/2008, 02h44
  3. [Système] Notice: Undefined offset
    Par noname_971 dans le forum Langage
    Réponses: 2
    Dernier message: 22/01/2008, 14h02
  4. [Tableaux] Notice: Undefined offset: 5 in
    Par fast462 dans le forum Langage
    Réponses: 3
    Dernier message: 30/05/2007, 10h08
  5. erreur: "Notice: Undefined offset:"
    Par Sh1v3r dans le forum Langage
    Réponses: 2
    Dernier message: 17/06/2006, 22h48

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo