Как зацикливание работает с разрывом строки в FPDF в PHP? - PullRequest
1 голос
/ 12 марта 2020

Я работаю над созданием документа PDF через php, но по моему для l oop все печатается в той же строке, а не в следующей строке,

Вот мой код -

for($i=0;$i<count($_GET);$i++){
    if(trim($_GET[$i])!="") {
        $printQueryResult = runPrintQuery($_GET[$i]);
        $totalRows = mysql_num_rows($printQueryResult);
        $resultArrayIndex = mysql_fetch_array($printQueryResult);

        //Headline of index
        $pdf->setXY(40, 41);
        $pdf->SetFillColor(238, 236, 225);
        $pdf->SetFont('Arial', '', 8);
        $pdf->Cell(25, 6, formatPubDate($resultArrayIndex['title']), 0, 0, 'L', True);
    }
} 

Вот мой вывод

Wrong Output

и вот что я пытаюсь достичь

Correct one

каждый текст в новой строке.

1 Ответ

0 голосов
/ 12 марта 2020

Попробуйте это:

$pdf->setXY(40, 41); // put this line outside loop
for($i=0;$i<count($_GET);$i++){
    if(trim($_GET[$i])!="") {
        $printQueryResult = runPrintQuery($_GET[$i]);
        $totalRows = mysql_num_rows($printQueryResult);
        $resultArrayIndex = mysql_fetch_array($printQueryResult);
        //Headline of index
        $pdf->SetFillColor(238, 236, 225);
        $pdf->SetFont('Arial', '', 8);
        $pdf->Cell(25, 6, formatPubDate($resultArrayIndex['title']), 0, 0, 'L', True);
        $pdf->Ln(); // aply new line
    }
}
...