FPDF无法从表外部显示数据库中的数据 [英] FPDF Display Data From Database Outside The Table Doesn't Work

查看:82
本文介绍了FPDF无法从表外部显示数据库中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在表的外部和内部显示数据.当我尝试在表内部调用数据时,它可以正常工作,但是当我在表外部调用数据时,它突然不显示.这部分就在这里...

I'm displaying a data outside and inside the table. When I tried to call the data on inside the table, it works perfectly fine but when I call it outside, it suddenly doesn't show. This part right here...

$pdf->MultiCell(194,4,"STORM SURGE INFORMATION",0,'C', false);
$pdf->Cell(191,4,"STORM SURGE: WARNING # ",0,0,'C');
$pdf->Cell(-136,4,$fetch['warning'],0,1,'C');

$pdf->Cell(172,4,"FOR: TYPHOON ",0,0,'C');
$pdf->Cell(-119,4,$fetch['typhoon'],0,1,'C');

$pdf->Cell(175,4,"ISSUED AT ",0,0,'C');
$pdf->Cell(-135,4,$fetch['date'],0,1,'C');

我的PDF当前看起来像这样.

My PDF currently look like this.

有人可以帮我弄清楚我的代码有什么错误或遗漏吗?

Can somebody help me figure out what is wrong or missing with my codes?

<?php

require("con.php");

$sql="SELECT * FROM table ORDER BY ssh REGEXP '^[^A-Za-z0-9]' ASC, ssh DESC";

$records=mysql_query($sql);
$fetch = $records[0];

require("library/fpdf.php");

class PDF extends FPDF{
  function Header(){
  }
  function Footer(){
  }
}

$pdf = new PDF('p', 'mm', 'Legal');
$title = 'Storm Surge Warning';
$pdf->SetTitle($title);
$pdf->AliasNbPages('{pages}');
$pdf->SetAutoPageBreak(true,40);

$pdf->AddPage();
$pdf->Ln();

$pdf->SetFont('Arial', 'B', 10);

$pdf->MultiCell(194,4,"STORM SURGE INFORMATION",0,'C', false);
$pdf->Cell(191,4,"STORM SURGE: WARNING # ",0,0,'C');
$pdf->Cell(-136,4,$fetch['warning'],0,1,'C');

$pdf->Cell(172,4,"FOR: TYPHOON ",0,0,'C');
$pdf->Cell(-119,4,$fetch['typhoon'],0,1,'C');

$pdf->Cell(175,4,"ISSUED AT ",0,0,'C');
$pdf->Cell(-135,4,$fetch['date'],0,1,'C');

$pdf->Ln(1);

$pdf->SetBorders(array('LT', 'LT', 'LT', 'LT', 'TLR'));
$pdf->SetWidths(array(25, 27, 35, 54, 53));
$pdf->SetAligns(array('C', 'C', 'C', 'L', 'L'));

$pdf->SetFont('Arial', 'B', 10);

$pdf->Row(array("SS Height",
            "Provinces",
            "Low Lying Coastal Areas in the Municipalities of:",
            "IMPACTS",
            "ADVICE/Actions to Take"), 1);

$pdf->SetFont('Arial', '', 11);


while($row = mysql_fetch_array($records)){
  $pdf->Row(array($row['ssh'],
  $row['provi'],
  $row['muni'],
  $row['impact'],
  $row['advice']), 1);
  }

$pdf->SetBorders(array('T', 'T', 'T', 'T', 'T'));
$pdf->Row(array('','','','',''), 1, false, 1);

$pdf->OutPut();
?>

推荐答案

在您的代码中,您正在获取一行数据,但是在开始while循环之前,您并未将包含该数据的行添加到PDF中.在设置字体之后,在while循环之前,添加如下所示的$pdf->Row位.

Early in your code you are fetching a row of data but you aren't adding the row to the PDF with that data before you start your while loop. Right after you set the font and before the while loop make the add the $pdf->Row bit shown below.

$pdf->MultiCell(194,4,"STORM SURGE INFORMATION",0,'C', false); 
$pdf->Cell(191,4,"STORM SURGE: WARNING # ",0,0,'C'); 
$pdf->Cell(-136,4,$fetch['warning'],0,1,'C'); 
$pdf->Cell(172,4,"FOR: TYPHOON ",0,0,'C'); 
$pdf->Cell(-119,4,$fetch['typhoon'],0,1,'C'); 
$pdf->Cell(175,4,"ISSUED AT ",0,0,'C'); 
$pdf->Cell(-135,4,$fetch['date'],0,1,'C');

$pdf->SetFont('Arial', '', 11);

$pdf->Row(array($fetch['ssh'],
    $fetch['provi'],
    $fetch['muni'],
    $fetch['impact'],
    $fetch['advice']), 1);

while($row = mysql_fetch_array($records)){
  $pdf->Row(array($row['ssh'],
  $row['provi'],
  $row['muni'],
  $row['impact'],
  $row['advice']), 1);
}

这篇关于FPDF无法从表外部显示数据库中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆