dongxian0320 2017-07-29 13:41
浏览 36

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

I have an issue, I have retrieved all the details of a row into pdf page but the issue is, when i click it echo's the id in the browser but not the specific id record from database.

On a little change, shows first row from mysql on every id button clicked.

Sometime displays all the record on the PDF page.

Example: If one record covers 2 pages of PDF page then it shows like 10 pages of all the rows showing in pdf page.

When I change the sql query like Select * from students where id = '$id' then this gives this error.

(Undefined variable: id in C:\xampp\htdocs\login Registration system\admin\includes\pdf\index.php on line 13)

Please help me out .

Its the Button from Where i call the pdf page:

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

Now its the PDF index page :

<?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();
}?>
  • 写回答

1条回答 默认 最新

  • donglun1918 2017-07-30 07:37
    关注

    Thankyou so much for your comments, I have solved it out by myself. The Issue was i was calling the action but in the index page there was no action.

    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();
      }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 html5+css有人可以帮吗?
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?