如何摆脱fpdf中找不到的'dbobject'?

hkmswyz6  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(178)

我已经尝试了很多方法来解决这个问题,但是作为初学者,使用fpdf框架创建pdf是很困难的。这是我的php代码。

//generate_pdf.php
<?php
//include connection file 
include_once("dbConnection.php");
include_once('fpdf.php');

class PDF extends FPDF
{
// Page header
function Header()
{
    // Logo
    $this->Image('image/logo.jpg',10,-1,70);
    $this->SetFont('Arial','B',13);
    // Move to the right
    $this->Cell(80);
    // Title
    $this->Cell(80,10,'Employee 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');
}
}

$db = new dbObj();
$connString =  $db->getConnstring();
$display_heading = array('email'=>'Email', 'score'=> 'Score',);

$result = mysqli_query($connString, "SELECT email, score FROM rank") or die("database error:". mysqli_error($connString));
$header = mysqli_query($connString, "SHOW columns FROM rank");

$pdf = new PDF();
//header
$pdf->AddPage();
//foter page
$pdf->AliasNbPages();
$pdf->SetFont('Arial','B',12);
foreach($header as $heading) {
$pdf->Cell(40,12,$display_heading[$heading['Field']],1);
}
foreach($result as $row) {
$pdf->Ln();
foreach($row as $column)
$pdf->Cell(40,12,$column,1);
}
$pdf->Output();

?>

//account.php
$q=mysqli_query($con,"SELECT * FROM rank  ORDER BY score DESC " )or die('Error223');
echo  '<div class="panel title"><div class="table-responsive">

<form class="form-inline" method="post" action="generate_pdf.php">
<button type="submit" id="pdf" name="generate_pdf" class="btn btn-primary"><i class="fa fa-pdf"" aria-hidden="true"></i>
Generate PDF</button>
</form>

<table class="table table-striped title1" >
<tr style="color:red"><td><b>Rank</b></td><td><b>Name</b></td><td><b>Gender</b></td><td><b>College</b></td><td><b>Course</b></td><td><b>Score</b></td></tr>';

//dbConnection.php
    < ?php $con= new mysqli('localhost','root','','thesis')or die("Could not connect to mysql".mysqli_error($con));                                                               
   function getConnstring() {
$con = mysqli_connect($this->dbhost, $this->username, $this->password, $this->dbname) or die("Connection failed: " . mysqli_connect_error());

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
} else {
$this->conn = $con;
}
return $this->conn;
}
}    
?>

这是我的问题的截图(错误信息):截图(错误信息)
以下是我的数据库截图:以下是我的数据库截图:
我很感激你们的想法。谢谢。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题