I'm trying to loop through an JSON array in PHP
and fill a fpdf table
My constructed string is valid JSON and looks like this:
[
{"ap":"j4","la":"02.02.2012","tr":"30 Tage","tra":"19.95EUR"},
{"ap":"de","la":"27.09.2012","tr":"30 Tage","tra":"19.95EUR"},
...
]
Which I'm setting as
if($rvar_apps != ""){
$activeAppsJson = json_decode( $rvar_apps ,true);
}
And then I'm trying this, which blanks the page:
if( $activeAppsJson ){
for($activeAppsJson as $item) {
$pdf->Cell(25,8,$item['ap'],1,0);
$pdf->Cell(25,8,$item['la'],1,0);
$pdf->Cell(25,8,$item['tr'],1,0);
$pdf->Cell(35,8,$item['tra'],1,1);
}
}
Having never worked with php before... I need some help!
Question :
What's wrong with my loop and variables assignment. The assigment seems to work, but the blank page doesn't tell me what's wrong in my loop...
THANKS!
It should be foreach instead of for
foreach($activeAppsJson as $item) {
$pdf->Cell(25,8,$item['ap'],1,0);
$pdf->Cell(25,8,$item['la'],1,0);
$pdf->Cell(25,8,$item['tr'],1,0);
$pdf->Cell(35,8,$item['tra'],1,1);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.