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 :

Warning : Illegal string offset


Sujet :

Langage PHP

  1. #1
    Membre éclairé
    Femme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2010
    Messages
    414
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Octobre 2010
    Messages : 414
    Par défaut Warning : Illegal string offset
    Bonjour

    Aidez-moi svp j'ai un code qui génère cette erreur :

    J'ai un foreach dans mon code comme ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    foreach ($resultat1 as $req)
    et
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $resultat1= $resFC1->fetch(PDO::FETCH_ASSOC);
    ===>
    array(8) { ["id"]=> string(1) "1" ["num"]=> string(5) "num 1" ["numtva"]=> string(0) "" ["client"]=> string(8) "client 1"["datefacture"]=> string(10) "27/03/2018" ["facturede"]=> string(12) "facture de 1" ["conditions"]=> string(12) "conditions 1"
    ["id_membre"]=> string(1) "3" }
    Par exemple pour j'obtiens ce warning:
    Warning: Illegal string offset 'facturede' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on
    line
    58
    En dessous tout mon code et erreurs:

    Warning: Illegal string offset 'client' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    51
    string(1) "1"
    Warning
    : Illegal string offset 'facturede' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on
    line
    58
    Warning
    : Illegal string offset 'client' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    64
    Warning
    : Illegal string offset 'num' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    71
    Warning
    : Illegal string offset 'datefacture' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on
    line
    72
    Warning
    : Illegal string offset 'client' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    51
    string(1) "n"
    Warning
    : Illegal string offset 'facturede' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on
    line
    58
    Warning
    : Illegal string offset 'client' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    64
    Warning
    : Illegal string offset 'num' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    71
    Warning
    : Illegal string offset 'datefacture' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on
    line
    72
    Warning
    : Illegal string offset 'client' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    51
    string(0) ""
    Warning
    : Illegal string offset 'facturede' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on
    line
    58
    Warning
    : Illegal string offset 'client' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    64
    Warning
    : Illegal string offset 'num' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    71
    Warning
    : Illegal string offset 'datefacture' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on
    line
    72
    Warning
    : Illegal string offset 'client' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    51
    string(1) "c"
    Warning
    : Illegal string offset 'facturede' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on
    line
    58
    Warning
    : Illegal string offset 'client' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    64
    Warning
    : Illegal string offset 'num' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    71
    Warning
    : Illegal string offset 'datefacture' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on
    line
    72
    Warning
    : Illegal string offset 'client' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    51
    string(1) "2"
    Warning
    : Illegal string offset 'facturede' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on
    line
    58
    Warning
    : Illegal string offset 'client' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    64
    Warning
    : Illegal string offset 'num' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    71
    Warning
    : Illegal string offset 'datefacture' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on
    line
    72
    Warning
    : Illegal string offset 'client' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    51
    string(1) "f"
    Warning
    : Illegal string offset 'facturede' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on
    line
    58
    Warning
    : Illegal string offset 'client' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    64
    Warning
    : Illegal string offset 'num' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    71
    Warning
    : Illegal string offset 'datefacture' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on
    line
    72

    Warning
    : Illegal string offset 'client' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    51
    string(1) "c"
    Warning
    : Illegal string offset 'facturede' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on
    line
    58
    Warning
    : Illegal string offset 'client' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    64
    Warning
    : Illegal string offset 'num' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    71
    Warning
    : Illegal string offset 'datefacture' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on
    line
    72
    Warning
    : Illegal string offset 'client' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    51
    string(1) "3"
    Warning
    : Illegal string offset 'facturede' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on
    line
    58
    Warning
    : Illegal string offset 'client' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    64
    Warning
    : Illegal string offset 'num' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on line
    71
    Warning
    : Illegal string offset 'datefacture' in
    /homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
    on
    line
    72
    Voici mon code :
    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
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    <?phprequire_once 'connexion.php';
    date_default_timezone_set('Europe/Berlin');
    require_once dirname(__FILE__).'/vendor/autoload.php';
    require_once 'connexion.php';
     
     
    use Spipu\Html2Pdf\Html2Pdf;
    ob_start();
    $str = '
        <page backtop="20mm" backright="10mm" backbottom="20mm" backleft="10mm">
        <style type="text/css">
        <!--
        table{width: 100%; border-collapse:collapse; font-size:18px}
        .header td{width: 50%; vertical-align: top}
        .text-left{text-align: left}
        .text-right{text-align: right}
        .text-center{text-align: center}
        .separator{height: 50px; width: 100%}
        .content td{border:solid 1px #CFD1D2; padding: 5px;}
        .content th{border:solid 1px #000000; padding: 5px; background-color: #000000; color: #FFFFFF}
        .ligne1Content{background-color:#57B223}
        .couleurgris{background-color:#DDDDDD; height:auto;}
        .tht, .taxe, .ttc{font-size: 1.2em;}
        .ttc{color:#57B223}
        .couleurverte{background-color: #57B223}
        .couleurmoinsgris{background: #EEEEEE;}
        .taille1{width:30%;}
        .taille2{width:15%;}
        .taille3{width:25%; }
        .taille4{width:20%;}
        .taille5{width:10%;}
        .header1{width:50%}
        .header2{width:50%}
        .tailleligne{height:200px}
        .taille1, taille2, taille3, taille4, taille5{height:auto;}
        -->
        </style>
    ';
     
     
    $resFC1=$base->prepare("SELECT * FROM infosfacture WHERE num= ?");
    $resFC1->bindValue(1, $id, PDO::PARAM_INT);
    $resFC1->execute(array($_GET['num']));
     
     
    $resultat1= $resFC1->fetch(PDO::FETCH_ASSOC);
     
     
    var_dump($resultat1);
     
     
    foreach ($resultat1 as $req){
        //$conditions = $req['conditions'];
    //var_dump($req['facturede']);
    var_dump($req['client']);
    //var_dump($req['num']);
    //var_dump($req['datefacture']);
        $str .= '
            <table class="header">
                <tr>
                    <td class="text-left"></td>
                    <td class="text-right"><b>'.$req['facturede'].'</b><br></td>
                </tr>
            </table>
            <div class="separator"></div>
            <table class="header">
                <tr>
                    <td class="text-left"><b>'.$req['client'].'</b><br></td>
                    <td class="text-right"></td>
                </tr>
            </table>
            <div class="separator"></div>
            <table>
                <tr>
                    <td class="text-left header1">N° de facture: <b>'.$req['num'].'</b>  </td>
                    <td class="text-right header2">Date: <b>'.$req['datefacture'].'</b></td>
               </tr>
            </table>
    
    
        ';
    //}
     
     
    $str .= '
        <br/><br/>
        <table class="content">
        <thead>
        <tr class="ligne1Content">
            <td class="text-left couleurgris taille1"><b>DESIGNATION</b></td>
            <td class="text-center couleurmoinsgris taille2"><b>QUANTITE</b></td>
            <td class="text-center couleurgris taille3"><b>PRIX HT</b></td>
            <td class="text-center couleurgris taille5"><b>TAXE</b></td>
            <td class="text-center couleurverte taille4"><b>TOTAL HT</b></td>
        </tr>
        </thead>
        <tbody>
    ';
     
     
    $resFC = $base->prepare('SELECT infosfacture.num, infosfacture.client, infosfacture.datefacture, infosfacture.facturede, infosfacture.conditions, facturation.designation, facturation.quantite, facturation.prixht, facturation.taxe
        FROM infosfacture
        INNER JOIN facturation
        ON infosfacture.num=? AND facturation.fk_facturation_id=infosfacture.id');
    $resFC->execute(array($_GET['num']));
     
     
    $resultat= $resFC->fetchAll();
     
     
    $somme = 0;
    foreach ($resultat as $req):
        $str .= '
            <tr class="couleurgris">
              <td class="text-left couleurgris taille1">'.$req['designation'].'</td>
              <td class="text-center couleurmoinsgris taille2">'.$req['quantite'].'</td>
              <td class="text-center taille3">'.$req['prixht'].'</td>
              <td class="text-center taille5">'.$req['taxe'].'</td>
              <td class="text-center couleurverte taille4">'.($req['quantite'] * $req['prixht']).'</td>
            </tr>
        ';
    $sommeht += $req['prixht'] * $req['quantite'];
    endforeach;
     
     
    $str .= '
        </tbody>
        <tfoot>
            <tr>
            <td colspan="4" class="text-right tht">TOTAL HT</td>
            <td class="tht text-center">'.$sommeht.'</td>
            </tr>';
            $sommetaxe = 0;
            foreach ($resultat as $req):
              $prixtotalht=$req['prixht'] * $req['quantite'];
              $prixtaxe=$prixtotalht * $req['taxe']/100;
          $str .= '
          <tr>
              <td colspan="4" class="text-right tht">TAXE à '.$req['taxe'].' % </td>
              <td class="text-center">'.$prixtaxe.' </td>
          </tr>
          ';
     
     
            $sommetaxe += $prixtaxe ;
            endforeach;
     
     
            $str .= '
            <tr>
              <td colspan="4" class="text-right tht">TOTAL TTC</td>
              <td class="text-center">'.($sommeht + $sommetaxe).'</td>
            </tr>
    
    
            <tr>
            <td colspan="5"><h3>Conditions et moyens de paiement:</h3><br/>'.$req['conditions'].'</td>
            </tr>
        </tfoot>
        </table>
        ';
        }
        $str .= ' </page> ';
     
     
    /*
     * On instancie notre constructeur
     * On affiche le contenu
     * On génére notre PDF
     */
     
     
     $str = ob_get_clean();
     
     
    $pdf = new HTML2PDF('P','A4','fr','true','UTF-8');
    $pdf->writeHTML($str);
    $pdf->Output('facture.pdf');
    ?>

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    1- Dans chaque message se trouve le numéro de ligne : "....line 58 "
    La 1ère chose est donc de REGARDER ce qui se passe à cette ligne (et aux lignes juste au dessus).

    2- Rien que l'affichage de var_dump($resultat1); : on voit bien qu'il n'y a QU'UN SEUL résultat !
    Ca devrait DEJA te mettre la puce à l'oreille...
    Dernière modification par Invité ; 12/04/2018 à 21h43.

  3. #3
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Par défaut
    Tu récupères une seule ligne de résultat par $resultat1= $resFC1->fetch(PDO::FETCH_ASSOC); et ensuite tu essayes de boucler dessus.
    Soit tu récupères l'ensemble des lignes en utilisant fetchAll et tu boucles sur le tableau résultant avec foreach, soit tu récupères une seule ligne et tu supprimes la boucle foreach.
    Modératrice PHP
    Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)
    Cherchez un peu avant poser votre question : Cours et Tutoriels PHP - FAQ PHP - PDO une soupe et au lit !.

    Affichez votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur) et [C=php][/C]

  4. #4
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Bonjour,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    $resFC1=$base->prepare("SELECT * FROM infosfacture WHERE num= ?");
    $resFC1->bindValue(1, $id, PDO::PARAM_INT); // d'où vient la variable
    $resFC1->execute(array($_GET['num'])); // Tu as déjà assigné la valeur $id dans sur la ligne précédente
     
     
    $resultat1= $resFC1->fetch(PDO::FETCH_ASSOC); // ça ne retourne que la première ligne s'il y a, vu le reste du code, ça doit être fecthall()
    EDIT: grillé par Celira

    A+.

  5. #5
    Membre éclairé
    Femme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2010
    Messages
    414
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Octobre 2010
    Messages : 414
    Par défaut
    Desolée de répondre tard ! J'avais plusieurs problèmes dans mon code et mon serveur. Maintenant tout fonctionne nickel, j'ai mon fichier pdf généré.
    Effectivement il ne fallait pas faire un foreach sur un fetch !

    Merci pour votre aide !

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

Discussions similaires

  1. Warning: Illegal string offset 'type'
    Par oitsuki dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 15/03/2018, 00h37
  2. Réponses: 2
    Dernier message: 10/10/2017, 17h07
  3. [PHP 7] Trouver la valeur dans un tableau (array) : Illegal string offset
    Par tonton.odilon dans le forum Langage
    Réponses: 2
    Dernier message: 06/07/2017, 19h55
  4. [MySQL] Warning: Illegal string offset
    Par neomega0304 dans le forum PHP & Base de données
    Réponses: 7
    Dernier message: 24/09/2016, 11h11
  5. Aide sur Warning: Illegal offset type in ...
    Par pounie dans le forum Langage
    Réponses: 5
    Dernier message: 03/01/2006, 13h13

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