PHP foreach行到2列
我需要生成基于PHP foreach结果的PDF页面,并显示2列A4 PDF横向模式。 例如,数据如下所示: 行数据1 行数据2 行数据3 行数据4 行数据5 行数据6 如果高度超过PDF第1列HTML表格中的高度,它将移动到页面的第2列,如下所示: 行数据1行数据7 行数据2行数据8 行数据3行数据9 行数据4 行数据5 行数据6 我的代码:PHP foreach行到2列,php,html,pdf,foreach,html-table,Php,Html,Pdf,Foreach,Html Table,我需要生成基于PHP foreach结果的PDF页面,并显示2列A4 PDF横向模式。 例如,数据如下所示: 行数据1 行数据2 行数据3 行数据4 行数据5 行数据6 如果高度超过PDF第1列HTML表格中的高度,它将移动到页面的第2列,如下所示: 行数据1行数据7 行数据2行数据8 行数据3行数据9 行数据4 行数据5 行数据6 我的代码: <table width="100%" cellspacing="0" cellpadding="0" border="0">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<thead>
<tr>
<th width="140px">Subject</th>
<th width="100px">Teacher</th>
<th width="8%">Exam</th>
</tr>
</thead>
<tbody>
<?php
foreach($data as $std)
{
?>
<tr>
<td><?php echo $std->data1; ?></td>
<td><?php echo $std->data2; ?></td>
<td><?php echo $std->data3; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
像这样试试
require('fpdf.php');//download fpdf and include
$pdf = new FPDF();
$myarray = array(1,2,3);
$pdf->SetFont('Arial','B',16);
foreach($myarray as $value){
$pdf->AddPage();
$pdf->Cell(40,10,$value);
}
$pdf->Output()
A4实际上是高度:297mm,宽度:210mm,对于纵向web,请点击此链接了解更多信息。因此,对于景观而言,其高度为210毫米,宽度为297毫米。我已经给了你一个大概的代码。修改$max_行,确定一个页面可以包含多少行而不会中断。并设置表格、列和行的“高度-宽度”属性的样式,以支持您的需要
<!DOCTYPE html>
<html>
<head>
<style>
body {
height: 210mm;
width: 297mm;
/* to centre page on screen*/
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body>
<table style="float:left;" width="50%" cellspacing="0" cellpadding="0" border="0">
<thead>
<tr>
<th width="140px">Subject</th>
<th width="100px">Teacher</th>
<th width="8%">Exam</th>
</tr>
</thead>
<tbody>
<?php
$max_rows = 6;
$count_row = 0;
foreach($data as $std)
{
$count_row++;
if($count_row > $max_rows)
$count_row = 0;
if($count_row == 0) {
?>
</tbody>
</table>
<table style="float:left;" width="50%" cellspacing="0" cellpadding="0" border="0">
<thead>
<tr>
<th width="140px">Subject</th>
<th width="100px">Teacher</th>
<th width="8%">Exam</th>
</tr>
</thead>
<tbody>
<?php } ?>
<tr>
<td><?php echo $std->data1; ?></td>
<td><?php echo $std->data2; ?></td>
<td><?php echo $std->data3; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</body>
</html>
那么,您的问题是什么?您以前尝试过什么?它不会移动到特定行数后的第二列。