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 :

récupérer les valeur dans un tableau d'object et d'un simple valeur ?


Sujet :

Langage PHP

  1. #1
    Débutant Avatar de razily
    Inscrit en
    Février 2009
    Messages
    376
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 376
    Points : 154
    Points
    154
    Par défaut récupérer les valeur dans un tableau d'object et d'un simple valeur ?
    Bonjour à tous ; voilà je tente de récupérer a valeur d'un tableau muni d'object et aussi d'un valeur nombre de ligne ici (ligne )
    après avoir fait var_dump($rows) j'ai çà

    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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
     
    array
      0 => 
        object(stdClass)[21]
          public 'id' => string '89' (length=2)
          public 'nom' => string 'zoro' (length=4)
          public 'prix' => string '12460.00' (length=8)
          public 'nom_marques' => string 'Adidas' (length=6)
          public 'nom_path' => string '1839c482d938d8555c07b4d9579fbbb5.jpg' (length=36)
          public 'quantite' => string '2' (length=1)
          public 'semelle_interieure' => string '1' (length=1)
          public 'libelle_fermeture' => string 'Lacets' (length=6)
          public 'libelle_style' => string 'Ballerines' (length=10)
          public 'libelle_talon' => string 'talon' (length=5)
          public 'libelle_doublure' => string 'cuir' (length=4)
          public 'libelle_semelle' => string 'caoutchouc' (length=10)
          public 'libelle_dessus' => string 'cuir' (length=4)
      1 => 
        object(stdClass)[22]
          public 'id' => string '87' (length=2)
          public 'nom' => string 'adizero' (length=7)
          public 'prix' => string '124000.00' (length=9)
          public 'nom_marques' => string 'Nike' (length=4)
          public 'nom_path' => string '1fc821480436f2264883b04481ab17dc.jpg' (length=36)
          public 'quantite' => string '12' (length=2)
          public 'semelle_interieure' => string '0' (length=1)
          public 'libelle_fermeture' => string 'Lacets' (length=6)
          public 'libelle_style' => string 'Ballerines' (length=10)
          public 'libelle_talon' => string 'talon' (length=5)
          public 'libelle_doublure' => string 'cuir' (length=4)
          public 'libelle_semelle' => string 'caoutchouc' (length=10)
          public 'libelle_dessus' => string 'cuir' (length=4)
      2 => 
        object(stdClass)[23]
          public 'id' => string '86' (length=2)
          public 'nom' => string 'zero' (length=4)
          public 'prix' => string '120555.00' (length=9)
          public 'nom_marques' => string 'Nike' (length=4)
          public 'nom_path' => string '14f269088af23675462ab0ed9d1c37bc.jpg' (length=36)
          public 'quantite' => string '2' (length=1)
          public 'semelle_interieure' => string '1' (length=1)
          public 'libelle_fermeture' => string 'Lacets' (length=6)
          public 'libelle_style' => string 'Ballerines' (length=10)
          public 'libelle_talon' => string 'talon' (length=5)
          public 'libelle_doublure' => string 'cuir' (length=4)
          public 'libelle_semelle' => string 'caoutchouc' (length=10)
          public 'libelle_dessus' => string 'cuir' (length=4)
      3 => 
        object(stdClass)[24]
          public 'id' => string '85' (length=2)
          public 'nom' => string 'zero' (length=4)
          public 'prix' => string '1245000.00' (length=10)
          public 'nom_marques' => string 'Adidas' (length=6)
          public 'nom_path' => string '146e3ba78d35e74999485febc3b34282.jpg' (length=36)
          public 'quantite' => string '2' (length=1)
          public 'semelle_interieure' => string '0' (length=1)
          public 'libelle_fermeture' => string 'A enfiler' (length=9)
          public 'libelle_style' => string 'Ballerines' (length=10)
          public 'libelle_talon' => string 'plat' (length=4)
          public 'libelle_doublure' => string 'textile' (length=7)
          public 'libelle_semelle' => string 'caoutchouc' (length=10)
          public 'libelle_dessus' => string 'cuir' (length=4)
      4 => 
        object(stdClass)[25]
          public 'id' => string '82' (length=2)
          public 'nom' => string 'adidas zero' (length=11)
          public 'prix' => string '125000.00' (length=9)
          public 'nom_marques' => string 'Adidas' (length=6)
          public 'nom_path' => string '7cb85ca12b5f31320b6c7a562fd0bc28.jpg' (length=36)
          public 'quantite' => string '2' (length=1)
          public 'semelle_interieure' => string '0' (length=1)
          public 'libelle_fermeture' => string 'A enfiler' (length=9)
          public 'libelle_style' => string 'Baskets' (length=7)
          public 'libelle_talon' => string 'plat' (length=4)
          public 'libelle_doublure' => string 'textile' (length=7)
          public 'libelle_semelle' => string 'caoutchouc' (length=10)
          public 'libelle_dessus' => string 'cuir' (length=4)
      'ligne' => int 5
    je ne sais pas comment faire pour récupérer id etc ...en faisant

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    foreach($rows as $r=>$value)
    {
      echo $r->id ; // id C un index dans le tableau 
     
    }
    pareil comment faire pour récupérer

    la ligne (nombre de ligne

    j'ai souvent un message d'erreur



    A PHP Error was encountered

    Severity: Notice

    Message: Trying to get property of non-object

    merci

  2. #2
    En attente de confirmation mail
    Homme Profil pro
    Développeur Web
    Inscrit en
    Décembre 2011
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Orne (Basse Normandie)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Décembre 2011
    Messages : 32
    Points : 54
    Points
    54
    Par défaut
    Bonjour,
    C'est normal que ça ne marche pas tu essaye d'extraire les données de l'index de ton tableau d'objets. Ce serait plutôt :
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    foreach($rows as $index=>$value)
    {
      echo $value->id ; //ici $value est ton objet
     
    }

  3. #3
    Débutant Avatar de razily
    Inscrit en
    Février 2009
    Messages
    376
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 376
    Points : 154
    Points
    154
    Par défaut
    Citation Envoyé par osore Voir le message
    Bonjour,
    C'est normal que ça ne marche pas tu essaye d'extraire les données de l'index de ton tableau d'objets. Ce serait plutôt :
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    foreach($rows as $index=>$value)
    {
      echo $value->id ; //ici $value est ton objet
     
    }
    merci

    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
     
     
    <?php if($rows!=null):
     
    				  foreach ($rows as $r=>$value): ?>
     
    						<h1>
    							<?php echo $value->id; ?>
    						</h1>
     
    				<?php endforeach;endif; ?>
     
     
    					<?php if($ligne!=null){
     
    						echo $ligne ;
     
    					}
     
    					?>

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

Discussions similaires

  1. Récupérer les valeurs dans un tableau
    Par ssxjim dans le forum Collection et Stream
    Réponses: 1
    Dernier message: 26/01/2011, 20h49
  2. [FirePHP] Récupérer les logs dans un tableau php
    Par Concombre Masqué dans le forum Bibliothèques et frameworks
    Réponses: 0
    Dernier message: 10/12/2010, 11h48
  3. Récupérer les informations dans un tableau
    Par schats dans le forum Langage
    Réponses: 12
    Dernier message: 21/11/2008, 19h19
  4. Réponses: 6
    Dernier message: 27/09/2006, 20h27
  5. Réponses: 1
    Dernier message: 05/09/2006, 17h56

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