我正在从 mySQL 表生成 PDF。生成的 PDF 适用于表中的所有值。我希望它特定于单行。例如下图中,我希望为 ID-2 生成 PDF。对于所有其他行也是如此。我附上了两个 php 脚本。fetch.php是我用Generate PDF按钮显示值的generate_pdf.php地方,也是我生成 PDF 的地方。
获取.php
<?php
//fetch.php
$connect = mysqli_connect("localhost", "id12", "", "id12");
$output = '';
$sql = "SELECT * FROM Datas WHERE ID LIKE '%" .$_POST["search"]."%'";
$result = mysqli_query($connect, $sql);
if(mysqli_num_rows($result) > 0)
{
$output .= '<h4 align = "center">Search Result</h4>';
$output .= '<div class="table-responsive">
<table class = "table table bordered">
<tr>
<th>ID</th>
<th>Name</th>
<th>Wrongs</th>
<th>Rights</th>
<th>Percentage</th>
<th>Age</th>
<th>Generate PDF</th>
</tr>';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>'.$row["ID"].'</td>
<td>'.$row["Name"].'</td>
<td>'.$row["Wrongs"].'</td>
<td>'.$row["Rights"].'</td>
<td>'.$row["Percentage"].'</td>
<td>'.$row["Age"].'</td>
<td><form class="form-inline" method="post" action="generate_pdf.php"></td>
<td><button type="submit" id="pdf" name="generate_pdf" class="btn btn-primary"><i class="fa fa-pdf"" aria-hidden="true"></i>Generate PDF</button></td>
</tr>
';
}
echo $output;
}
else
{
echo "Data not found";
}
?>
generate_pdf.php
<?php
//include connection file
include_once("connection.php");
include_once('fpdf/fpdf.php');
class PDF extends FPDF
{
// Page header
function Header()
{
}
// 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');
}
}
精慕HU