Reputation: 39
I want to call getstringwidth
already declared in another while
when using while
just for set width on next row.
My table heading :
while ($row2x = $stmt2x->fetch(PDO::FETCH_ASSOC)){
$string = $row2x['nama_kriteria'];
$cellwidth = $pdf->GetStringWidth($string);
$pdf->Cell($cellwidth + 2,7,$row2x['nama_kriteria'],1,0,'L');
}
how can I use table heading width for my next table row?
My table row :
while ($rowrx = $stmtrx->fetch(PDO::FETCH_ASSOC)){
$pdf->Cell(/*$cellwidth + 2*/,7,$rowrx['nilai_rangking'],1,0,'L');
}
any idea how to make it good-looking?
Upvotes: 1
Views: 403
Reputation: 30
try to store width in array.
$width = array();
while ($row2x = $stmt2x->fetch(PDO::FETCH_ASSOC)){
$string = $row2x['nama_kriteria'];
$cellwidth = $pdf->GetStringWidth($string);
$pdf->Cell($cellwidth + 2,7,$row2x['nama_kriteria'],1,0,'L');
$width[] = $cellwidth + 2;
}
$i = 0;
while ($rowrx = $stmtrx->fetch(PDO::FETCH_ASSOC))
{
$pdf->Cell($width[$i],7,$rowrx['nilai_rangking'],1,0,'L');
$i++;
}
you need to fill the width array you get from the $cellwidth = $pdf->GetStringWidth($string);
then you just use the value from that width from width variable
Upvotes: 1