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:
foreach ($resultat1 as $req)
et
Code:
$resultat1= $resFC1->fetch(PDO::FETCH_ASSOC);
Code:
var_dump($resultat1);
===>
Citation:
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
Code:
'.$req['facturede'].'
j'obtiens ce warning:
Citation:
Warning: Illegal string offset 'facturede' in
/homepages/0/d513201601/htdocs/Facturation_generale/imprimerpdf.php
on
line
58
En dessous tout mon code et erreurs:
Citation:
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:
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');
?> |