-1

i want to align my data properly in pdf file frm mysql database. but the result i get is not wat i want, some last column just come below the other while i wanted to align with the other column. i have tried something like this.

while (ob_get_level())
ob_end_clean();
header("Content-Encoding: None", true);




$host="localhost";
$user="root";
$password="";
$db_name="pdf_test";
$conn=mysql_connect($host,$user,$password) or die("cannot connect to the  
database".mysql_error());
mysql_select_db($db_name,$conn)or die("cannot select the database".mysql_error());


include('fpdf.php');

$q=mysql_query("select * from education_mailstone");
$number_of_persons=mysql_num_rows($q);

//initialize the 4 columns and the total
$column_name="";
$column_school="";
$column_year="";
$column_score="";

//For each row add field to the specific column
while($row=mysql_fetch_array($q)){
$name=$row['name'];
$school=$row['school'];
$year=$row['year'];
$score=$row['score'];


$column_name=$column_name.$name."\n";
$column_school=$column_school.$school."\n";
$column_year=$column_year.$year."\n";
$column_score=$column_score.$score."\n";
}



$pdf=new FPDF();
$pdf->AddPage();
$Y_Fields_Name_position=20;
$Y_Table_position=26;
$pdf->SetFillColor(232,232,232);
$pdf->SetFont('Arial','B',12);
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(10);
$pdf->Cell(400,6,'NAME OF STUDENT',1,0,'L',1);
$pdf->SetX(60);
$pdf->Cell(400,6,'NAME OF THE SCHOOL',1,0,'L',1);
$pdf->SetX(120);
$pdf->Cell(400,6,'COMPLETION YEAR',1,0,'L',1);
$pdf->SetX(180);
$pdf->Cell(50,6,'SCORE',1,0,'L',1);
$pdf->Ln();
$pdf->SetFont('Arial','',12);
$pdf->SetY($Y_Table_position);
$pdf->SetX(10);
$pdf->MultiCell(400,6,$column_name,1);
$pdf->SetY($Y_Table_position);
$pdf->SetX(60);
$pdf->MultiCell(400,6,$column_school,1);
$pdf->SetY($Y_Table_position);
$pdf->SetX(120);
$pdf->MultiCell(400,6,$column_year,1);
$pdf->SetX(180);
$pdf->MultiCell(50,6,$column_score,1);
$pdf->Ln();
$i = 0;
$pdf->SetY($Y_Table_position);
while ($i < $number_of_persons)
{
    $pdf->SetX(10);
    $pdf->MultiCell(120,6,'',1);
    $i = $i +1;
}
$pdf->Output();

so wat am i doin wrong?

4

1 回答 1

0

您是否正在尝试创建一个表格,其中标题水平穿过,名称和详细信息在下面的列中穿过?

如果是这样,我不确定您为什么将每个单元格的宽度设置为 400mm $pdf->Cell(400,6,'NAME OF STUDENT',1,0,'L',1);

看起来您正在尝试使用 SetX 功能使单元格宽 60 毫米?你有什么理由这样做而不是让你的代码作为 $pdf->Cell(60,6,'NAME OF STUDENT',1,0,'L',1); 这样你就不需要每次都 setX 并且下一个单元格“学校名称”应该自动排列在这个单元格的右侧?

那么对于你的MultiCell,你应该真的把它的宽度设为60 $pdf->MultiCell(60,6,$column_school,1);

如果这根本没有帮助,您也许可以上传它当前为您显示的内容的链接。

有关使用 FPDF 的一些基本信息,我最近写了一篇关于 FPDF 基础的博客,因为该网站的说明不太有用

http://www.limelightonline.co.nz/blog/create-dynamic-pdf-with-php-tutorial/

不确定这对您有帮助吗?

谢谢,谢伊。

于 2013-05-01T04:09:52.477 回答