Как избавиться от 'dbObject' не найден в fpdf? - PullRequest
0 голосов
/ 13 сентября 2018

Я много чего пробовал, чтобы решить эту проблему, но сложно создать pdf, используя fpdf framework как новичка. Вот мои 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;
}
}    
?>       

Вот скриншот (сообщение об ошибке) моей проблемы: снимок экрана (сообщение об ошибке)

Вот скриншот моей базы данных: Вот скриншот моей базы данных:

Я ценю все ваши мысли, ребята. Спасибо.

...