在PHP中,FPDF中的换行符如何使用循环?
我正在通过php制作PDF文档,但在我的for循环中,所有内容都在同一行中打印,而不是在下一行中打印 这是我的密码-在PHP中,FPDF中的换行符如何使用循环?,php,fpdf,Php,Fpdf,我正在通过php制作PDF文档,但在我的for循环中,所有内容都在同一行中打印,而不是在下一行中打印 这是我的密码- for($i=0;$i<count($_GET);$i++){ if(trim($_GET[$i])!="") { $printQueryResult = runPrintQuery($_GET[$i]); $totalRows = mysql_num_rows($printQueryResult); $resultA
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);
}
}
for($i=0;$isetXY(40,41);
$pdf->SetFillColor(238236225);
$pdf->SetFont('Arial','',8);
$pdf->Cell(25,6,formatPubDate($resultaryIndex['title']),0,0,'L',True);
}
}
这是我的输出
这就是我想要达到的目标
将每个文本换成一行。尝试以下操作:
$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
}
}
$pdf->setXY(40,41);//将这行放在循环外
对于($i=0;$iSetFillColor(238236225);
$pdf->SetFont('Arial','',8);
$pdf->Cell(25,6,formatPubDate($resultaryIndex['title']),0,0,'L',True);
$pdf->Ln();//使用新行
}
}
试试这个:
$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
}
}
$pdf->setXY(40,41);//将这行放在循环外
对于($i=0;$iSetFillColor(238236225);
$pdf->SetFont('Arial','',8);
$pdf->Cell(25,6,formatPubDate($resultaryIndex['title']),0,0,'L',True);
$pdf->Ln();//使用新行
}
}
您每次通过循环都设置相同的X和Y位置。警告:mysql
扩展多年来一直被弃用,并且在PHP 7.0中已被完全删除。您早就该升级了。您应该通过Cell()的loop.5th参数每次递增Y
值控制换行。当然,如果使用SetXY()强制定位,这将是无用的。@Barmar您能举个例子吗?您每次都在循环中设置相同的X和Y位置。警告:mysql
扩展多年来一直被弃用,并且在PHP 7.0中已被完全删除。您早就该升级了。您应该在粗略地循环。Cell()的第5个参数控制换行。当然,如果你用SetXY()强制定位,它将毫无用处。@Barmar你能给我举个例子吗?谢谢@benilson我们也可以在其中进行换行吗?使用$pdf->Ln();
。使用$pdf->Ln();单词可以在单元格内包装?谢谢@benilson我们也可以在单元格内包装单词吗?使用$pdf->Ln();
。使用$pdf->Ln();单词可以在单元格内包装?