是否可以在PHP FPDF上填充特定的行?

时间:2019-03-12 00:12:24

标签: php mysql pdf fpdf

所以我在考虑是否可以在fpdf中为行着色。方案是从数据库中提取一些数据,例如,第一行的标题为“ Height”,而数据库中所有高度为“ 2-3米”的数据,其行应着色为棕色。如果数据为“ 1-2米”,则该行应被着色为黄色

我实际上认为这是可能的,但是我只是不知道如何使其成为可能,因为我不知道它的确切语法。我尝试搜索一些教程和参考资料,但还是不明白。

我将在下面附加图片和我的pdf.php代码,以便您可以更多地了解我的问题。我希望你们能给我想法。

<?php

mysql_connect('server', 'username', 'password');

mysql_select_db('database');

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

$records=mysql_query($sql);

require("library/fpdf.php");

class PDF extends FPDF{
    function Header(){
    $this->SetFont('Arial', '', 10);
    $this->cell(12);
    $this->Image('logo.png',40,12,17);

    $this->Ln(5);
}
function Footer(){

    $this->SetY(-15);
    $this->setFont('Arial','',8);
    $this->cell(0,10,'Page '.$this->PageNo()." / {pages}",0,0,'C');
}
}

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

$pdf->AddPage();

$pdf->SetFont('Arial', 'B', 10);
$pdf->MultiCell(200,4,"   \nSTORM SURGE INFORMATION \nSTORM SURGE: WARNING #01 \nFOR: TYPHOON ROSITA (YUTU) \nISSUED AT 11AM, 29 October 2018 \n   ",1,'C', false);

$pdf->SetBorders(array('LT', 'LT', 'LT', 'LT', 'TLR'));
$pdf->SetWidths(array(30, 30, 40, 50, 50));
$pdf->SetAligns(array('C', 'C', 'C', 'C', 'C'));

$pdf->SetFont('Arial', 'B', 11);
$pdf->SetFillColor(100,100,125);

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

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

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();
?>

这就是我想要的输出。

enter image description here

0 个答案:

没有答案