dongliechuich10319 2017-01-06 15:26
浏览 37
已采纳

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

I am trying to generate a pdf form through below given script. When I generate the pdf file it only printing header and footer. I am unable to print values from database. db.php and fpdf.php are correct. Output is attached Please help.
enter image description here

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

    ?>
  • 写回答

1条回答 默认 最新

  • dongou4052 2017-01-07 08:59
    关注

    The problem is when you call the Cell method:

    $pdf->Cell(0,10,'Banner id:' , $row['banner_id']);
    

    you need to replace the comma with a period..!

    So this will work:

    $pdf->Cell(0,10,'Banner id:' . $row['banner_id']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看