php - FPDF - 如何更改 foreach php 中的单元格大小

标签 php mysql pdf include fpdf

http://phppot.com/php/generate-pdf-from-mysql-data-using-fpdf/ 我使用此代码,但它不起作用。

    <?php
require_once("dbcontroller.php");
$db_handle = new DBController();
$result = $db_handle->runQuery("SELECT * FROM toy");
$header = $db_handle->runQuery("SELECT `COLUMN_NAME` 
FROM `INFORMATION_SCHEMA`.`COLUMNS` 
WHERE `TABLE_SCHEMA`='blog_samples' 
    AND `TABLE_NAME`='toy'");

require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',12);      
foreach($header as $heading) {
    foreach($heading as $column_heading)
        $pdf->Cell(90,12,$column_heading,1);
}
foreach($result as $row) {
    $pdf->SetFont('Arial','',12);   
    $pdf->Ln();
    foreach($row as $column)
        $pdf->Cell(90,12,$column,1);
}
$pdf->Output();
?>

我想更改 foreach 命令,我想检查 mysql,当 $header 为“有趣”时,我希望单元格比其他单元格小一点。

我尝试使用if,但它不起作用 请帮忙!

最佳答案

要根据您的情况减小单元格的宽度,您可以执行以下操作:

<罢工>

<罢工>
// your code

foreach($header as $heading){
    foreach($heading as $column_heading){
        if($column_heading == "fun"){
            $pdf->Cell(45,12,$column_heading,1);
        }else{
            $pdf->Cell(90,12,$column_heading,1);
        }
    }
}

// your code

<罢工>

已编辑:

// your code

$pdf->SetFont('Arial','B',12); 
foreach($header as $heading){
    $counter = 1;
    foreach($heading as $column_heading){
        if($counter > 3){
             $pdf->Cell(45,12,$column_heading,1);
        }else{
             $pdf->Cell(90,12,$column_heading,1);
        }
        ++$counter;
    }
}

foreach($result as $row){
    $counter = 1;
    $pdf->SetFont('Arial','',12);   
    $pdf->Ln();
    foreach($row as $column){
        if($counter > 3){
            $pdf->Cell(45,12,$column,1);
        }else{
            $pdf->Cell(90,12,$column,1);
        }
        ++$counter;
    }
}
$pdf->Output();

引用资料如下:

关于php - FPDF - 如何更改 foreach php 中的单元格大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34530635/

相关文章:

PHP 客户端无法连接到本地主机上的 RabbitMQ 服务器

php - 在我的网站中自定义 RSS 提要

javascript - 删除sequelize中的单引号原始查询

php - 在 Yii2 搜索中比较匹配的数组索引值

mysql - WHERE IN 与 Doctrine 2 DBAL

python - 使用 imshow 时,Matplotlib PDF 输出不遵守 zorder

php - 使用 PHP linux 将 doc、docx、pdf 转换为 HTML

php - HTTP 请求的 keep_alive 和 persistent 选项有什么区别?

javascript - Jquery打印包含在字符串中的pdf

php - 将用户限制在他们的个人资料页面