在 PHP 中将数据库中的特定行详细信息显示到 PDF 页面中



我有一个问题,我已经将一行的所有详细信息检索到 pdf 页面中,但问题是,当我单击它时,回显浏览器中的 id 而不是数据库中的特定 id 记录。

稍作更改,在单击的每个 id 按钮上显示 mysql 的第一行。

有时显示 PDF 页面上的所有记录。

示例:如果一条记录覆盖 PDF 页面的 2 页,则它会显示 pdf 页面中显示的所有行中的 10 页。

当我像Select * from students where id = '$id'一样更改 sql 查询时,这会产生此错误。

(未定义的变量:C:\xampp\htdocs\login Registration 中的 id 系统\管理员\包含\pdf\索引.php在第 13 行(

请帮帮我.

它的按钮 我从哪里调用pdf页面:

<th scope="row"><a href="includes/pdf/index.php?action=select&id=<?php echo $id; ?>"  class="btn btn-success">Print</a></th>

现在是PDF索引页

<?php
require('library/fpdf.php');
include("pconnect.php");
$sql = "SELECT * FROM students ";
$result = mysqli_query($con, $sql);
while($rows = mysqli_fetch_array($result))
{
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 10);
$pdf->Ln();
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('times', 'B', 10);
$pdf->Cell(30, 20, 'Name on Passport', 1, 0);
$pdf->Cell(60, 10, $rows['firstname'], 1, 0, 'C');
$pdf->SetX(40);
$pdf->Cell(60, 10, $rows['lastname'], 1, 0, 'C');
$pdf->Cell(30, 10, 'Nationality', 1, 0, 'C');
$pdf->Cell(45, 10, $rows['nationality'], 1, 0, 'C');
$pdf->SetX(85);
$pdf->Cell(28, 10, 'Place of Birth', 1, 0);
$pdf->Cell(42, 10, $rows['placeofbirth'], 1, 1, 'C');
$pdf->Cell(30, 10, 'Date of Birth', 1, 0);
$pdf->Cell(73, 10, $rows['dateofbirth'], 1, 0, 'C');
$pdf->Cell(42, 10, $rows['gender'], 1, 0, 'C');
$pdf->SetY(60);
$pdf->SetX(155);
$pdf->Cell(45, 40, $rows['Photo'], 1, 1, 'C');
$pdf->Output();
}?>

非常感谢您的评论,我已经自己解决了。问题是我正在调用该操作,但在索引页面中没有操作。

if(($_GET['action'] == 'select') && isset($_GET['id'])) {
$id = $_GET['id'];
$sql = "Select * FROM students WHERE id = '$id'";
$query = mysqli_query($con, $sql);
$pdf=new FPDF();
$pdf->AddPage();
while($rows=mysqli_fetch_array($query))
{
$pdf->SetFont('Arial','B',10);
$pdf->Ln();
$pdf->Ln();
}
$pdf->Output();
}

最新更新