首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将mysql的数据打印到pdf文件中。页眉和页脚正在打印,但mysql的数据不是打印的。

如何将mysql的数据打印到pdf文件中。页眉和页脚正在打印,但mysql的数据不是打印的。
EN

Stack Overflow用户
提问于 2017-01-06 15:26:35
回答 1查看 2.1K关注 0票数 0

我试图通过下面的脚本生成一个pdf表单。当我生成pdf文件时,它只打印页眉和页脚。我无法从数据库打印值。 db.phpfpdf.php是正确的。输出附件请帮助。

代码语言:javascript
复制
<?php

    include "includes/db.php";

    require('includes/fpdf/fpdf.php');

    class PDF extends FPDF
    {
    // Page header
    function Header()
    {
    // Logo
    $this->Image('assets/img/find_user.png',10,6,30);
    // Arial bold 15
    $this->SetFont('Arial','B',12);
    // Move to the right
    $this->Cell(80);
    // Title
    $this->Cell(60,10,'Shekhat test',0,0,'C');
    // Line break
    $this->Ln(8);

    $this->SetFont('Arial','B',7);

    $this->Cell(220,10,'Pune, Maharashtra',0,0,'C');


    $this->Ln(30);

    $this->SetDrawColor(188,188,188);
    $this->Line(0,45,350,45);

    }

    // Page footer
    function Footer()
    {
    // Position at 1.5 cm from bottom
    $this->SetY(-15);
    // Arial italic 8
    $this->SetFont('Arial','I',8);
    // Page number
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
    }
    }



    // Instanciation of inherited class
    $pdf = new PDF();
    $pdf->AliasNbPages();
    $pdf->AddPage();
    $pdf->SetFont('Times','',12);


    if(isset($_GET['print_slider'])){ 

        $get_id = $_GET['print_slider'];


    $result="SELECT * FROM homeslider WHERE banner_id='$get_id'";
    //$result="SELECT * FROM homeslider";

    $rows = mysqli_query($con, $result); 


    while($row=mysqli_fetch_array($rows, MYSQLI_ASSOC))
    {

    $pdf->Cell(0,10,'Banner id:' ,$row['banner_id']); 
    $pdf->Ln();
    $pdf->Cell(0,10,'Banner Title:' ,$row['banner_title']);
    $pdf->Ln();
    $pdf->Cell(0,10,'Banner Image:' ,$row['banner_image']);

        }

    }
    $pdf->Output();

    ?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-07 08:59:54

问题是当您调用Cell方法时:

代码语言:javascript
复制
$pdf->Cell(0,10,'Banner id:' , $row['banner_id']);

你需要用句点替换逗号!

所以这是可行的:

代码语言:javascript
复制
$pdf->Cell(0,10,'Banner id:' . $row['banner_id']);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41508793

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档