php - 使用 PHP 和 FPDF 创建 PDF 文件时未获取所有列值

标签 php mysql fpdf

我正在创建一个 pdf 文件,使用 FPDF 从 MySQL 表中获取数据,但在我的情况下,所有列值均未显示在 PDF 文件中。我在下面提供我的代码。

require_once '../../../include/libs/fpdf.php';
class PDF extends FPDF{
    // Page header
    function Header(){
        // Logo
        $this->Image('../../../admin/img/HLW-CabManagementLogopdf.png',10,-1,30);
        $this->SetFont('Arial','B',13);
        // Move to the right
        $this->Cell(80);
        // Title
        $this->Cell(80,10,'Report List',1,0,'C');
        // Line break
        $this->Ln(20);
    }
    // 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');
    }

}
if ($_REQUEST["action"]=="downloadMonthlyReportData") {
        $data=array();
        $start_time=$_POST['start_time'];
        $end_time=$_POST['end_time'];
        $sql="select * from cb_wallet_driver_logs order by id desc";
        $stmt = $db->prepare($sql);
        if ($stmt->execute()) {
            $row = $stmt->fetchAll();
            $number_of_rows= count($row);
            if ($number_of_rows > 0) {
                $slno=1;
                foreach ($row as $key => $value) {
                    $last_update=$value['last_update'];
                    $owner_id=$value['owner_id'];
                    $sql="select * from cb_owner_info where owner_id=:owner_id";
                    $stmt = $db->prepare($sql);
                    $stmt->bindParam(':owner_id', htmlspecialchars(strip_tags($owner_id)));
                    if ($stmt->execute()) {
                        $orow = $stmt->fetchAll();
                        $number_of_orows= count($orow);
                        if ($number_of_orows > 0) {
                            foreach ($orow as $key => $val) {
                                $owner_name=$val['name'];
                            }
                        }
                    }
                    $dt = new DateTime($last_update);
                    $odate=$dt->format('d-m-Y');
                    $ndate=date('d-m-Y',strtotime($odate));
                    $stdate=date('d-m-Y',strtotime($start_time));
                    $endate=date('d-m-Y',strtotime($end_time));
                    if ($ndate >= $stdate && $ndate <= $endate) {
                        $data[]=array("sl_no"=>$slno,"owner_name"=>$owner_name,"last_update"=>$last_update,"book_id"=>$value['book_id'],"operator_total"=>$value['operator_total'],"ride_total"=>$value['ride_total']);
                        $slno++;
                    }
                }
            }
        }
        $result1=array();
        if (count($data) > 0) {
            $pdf = new PDF();
            //header
            $pdf->AddPage();
            //foter page
            $pdf->AliasNbPages();
            $pdf->SetFont('Arial','B',12);
            $column1=array("Sl No","Owner name","Date","Booking ID","Operator Total","Ride Total");
            //print_r($column1);exit;
            foreach ($column1 as $key => $value) {
                //echo $value.'<br>';
                $pdf->Cell(40,15,$value,1);
            }
            foreach ($data as $key => $value) {
                $pdf->Ln();
                foreach ($value as $column) {
                    //echo $column.'<br>';
                    $pdf->Cell(40,15,$column,1);
                }
            }
            $today = date('YmdHi');
            $filename='report_'.$today.'.pdf';
             $totalpath='/var/www/hlwcab.com/public_html/cab/service/admin/report/download/'.$filename;
            $pdf->Output($totalpath, "F");
            $result1["msg"] = "Succesfully Downloaded...";
        }else{
            header("HTTP/1.0 401 Unauthorized");
            $result1["msg"] = "No record to download...";
        }
        echo json_encode($result1);
    }

在这里,我从 MYSQL 表中获取数据并将其转换为 PDF,但在我的例子中,我缺少最后一列 (Ride Total) 值。我在下面附上我的文件。

enter image description here

这里还有一些列值穿过单元格,我需要调整它。我需要获取此 PDF 中的所有列值。

最佳答案

$sql="
SELECT c.olumns
     , I
     , actually 
     , w.ant
  FROM cb_wallet_driver_logs c
  JOIN cb_owner_info w
    ON w.owner_id=  c.owner_id
 ORDER
    BY c.id;
";
$stmt = $db->prepare($sql);
if ($stmt->execute()) {
...

或者类似的东西

关于php - 使用 PHP 和 FPDF 创建 PDF 文件时未获取所有列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56268554/

相关文章:

mysql - 从多个表中计数

php - 避免 fpdf 单元格中的重复项

php - FPDF 将带有背景颜色的文本添加到 x/y 坐标

php - 不推荐使用的 ping() Doctrine 的替代方案

php - Jquery 翻盖脚本未在翻盖背面显示独特内容

php - PDO连接不上,但是mysql_connect可以(没有PW)

c# - 使用包含 MySQL 数据库表的 c# 填充下拉列表

PHP 脚本为每个 SQL 行输出单独的 PDF - FPDF

php - Twilio 客户端 DTMF 不工作

带有屏幕和 Ts3Musicbot 的 PHP shell_exec