想要使用fpdf在新的pdf页面上显示每一行,但得到错误http错误500

时间:2016-10-27 08:44:45

标签: php mysql pdf fpdf

<?php



$host=""; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name 
$tbl_name="employees_table"; // Table name 
$tb2_name="payslip";
$tbincome="Added_income";
$tbp="Paye_deductions";
$tbq="Extra_deductions";
// Connect to server and select databse.
$conn = mysqli_connect("$host", "$username", "$password")or die("cannot connect"); 
mysqli_select_db($conn,"$db_name")or die("cannot select DB");


class PDF extends FPDF
{
    }

我想在新的pdf页面上显示每一行。 $ result6应该获取表中的所有行,并为每一行创建一个新的pdf页面。

下面的代码获取行数

 $result6=mysqli_query($conn,"SELECT * FROM $tb2_name WHERE Month = '$month1' AND Year = 'Year1' AND Company = '$company9'");
    while($row357 = mysqli_fetch_array($result6))

{
$pdf=new PDF();
$pdf->AddPage();
$pdf->Image('logo_new.png', 30, 40, 150);
$pdf->SetFont('Arial','',10);
$txt4 ="Employee Code :$Numb";
$txt="Name: $Name $Surname";
$txt3="Address : $Address";
$txt2="Account Number: $Account";
$txt5 ="Address : $Address";
$txt6 = "Bank :$Bank";
$txt7 = "Branch Number:$Branch";
$txt8 = "Job Tittle :$Job";
$txt9 = "Date Engaged: $Engaged";
$txt10 = "Job Grade : $Grade";
$txt11 = "Payment Date : $Month $Year";
$txt12 = "Company : $Company";
$txt13 = "Payslip Number : $Payslip_Number";
$text = "Earnings";
    $pdf->Cell(133.5, 2.7, $txt, 0, 0, 'L');
    $pdf->Cell(45.5, 3.7, $txt2, 0, 1, 'L');
    $pdf->Cell(133.5, 4.7, $txt4, 0, 0, 'L');
    $pdf->Cell(45.5, 3.7, $txt6, 0, 1, 'L');
    $pdf->Cell(133.5, 4.7, $txt5, 0, 0, 'L');
    $pdf->Cell(45.5, 3.7, $txt7, 0, 1, 'L');
    $pdf->Cell(133.5, 4.7, $txt8, 0, 0, 'L');
    $pdf->Cell(45.5, 3.7, $txt9, 0, 1, 'L');
    $pdf->Cell(133.5, 4.7, $txt10, 0, 0, 'L');
    $pdf->Cell(45.5, 3.7, $txt11, 0, 1, 'L');
    $pdf->Cell(133.5, 4.7, $txt12, 0, 0, 'L');
    $pdf->Cell(45.5, 3.7, $txt13, 0, 1, 'L');




$x = $pdf->GetX();
$y = $pdf->GetY();


$yt = $y + 5 ;
$yt9 = $yt + 10 ;
$pdf->setY($y +5);
$y_value = $y ; 
$x_value = $x;
$col1="Income\n\n Salary  \n Bonus   \n Housing Allow   \n Transport Allow   \n Travel Allow    \n Vehicle Allow   \n Cellphone_Allow   \n Entertainment   \n Company Car   \n Medical Allow   "; 
$col9="\n \n $Salary \n $Bonus \n $Housing_Allowance \n $Transport_Allowance \n $Travel_Allowance \n $Vehicle1 \n $Cellphone_Allowance \n $Entertainment_Allowance \n $Company_Car \n $Medical_Allowance   ";
$col4= " Cost To Company : $gross_Income                    Deductions : $totaldeductions                                        NetPay : $netpay \n  Tax paid:$Tax_Payable                                      Total Earning : $sum1                   Total Tax Paid : $sum \n Leave Details :Annual $Annual_Leave                         leave Taken : $Days_Taken                              Leave Accured : $Leave_Acquired ";
$col14 = " Total Earning : $sum1                        Total Tax Paid : $sum ";
$col5= " Leave Details :Annual $Annual_Leave                          leave Taken : $Days_Taken                              Leave Accured : $Leave_Acquired";      
$col8="\n \n    ";
$col12="PAYE Deductions \n \n Housing Allow \n Vehicle Allow \n Company Car   \n Contributions  \n Vehicle Allow   \n Pension   \n Provident Fund  \n Retirement Annuity  \n Study Policy \n ";
$col13="\n \n $Dhose \n $Vehicle_Allowance  \n $DCompany_Car \n $DContributions \n $DVehicle_Allowance \n $Pension \n $Provident_Fund \n $Retirement_Annuity \n  $Study_Policy ";

$sql = " SELECT * FROM $tbincome WHERE Month='$month' AND Year='$year' AND Employee_Number='$user1'";


$results99 = mysqli_query($conn, $sql);
$rows = mysqli_fetch_assoc($results99);
$removeKeys2 = array('ID', 'Employee_Number', 'Month', 'Year', 'Company', 'Status', 'payment_cycle', 'Payslip_Number', 'House1', 'closing', 'generated');

foreach($removeKeys2 as $key2) {
   unset($rows[$key2]);
}
$hg = " Income ";
$pdf->MultiCell(189, 10, $hg, 1, 1);


$data = array();
foreach($rows as $key => $value) {
  if($value > 0) {
    $me =  $key . "\n";
    $pdf->MultiCell(189, 10, $me, 1, 2);
  }
}
$pdf->SetXY(40, $yt9);
$pdf->SetX(48);
foreach($rows as $key => $value) {
  if($value > 0) {
    $me9 =  number_format($value) . "\n";
    $pdf->MultiCell(189, 10, $me9, 0, 2);
    $pdf->SetX(48);
  }
}
$pdf->SetXY($x + 35, $yt);

$wql = " SELECT * FROM $tbp WHERE Month='$month' AND Year='$year' AND Employee_Number='$user1'";

$results9 = mysqli_query($conn, $wql);
$rows4 = mysqli_fetch_assoc($results9);
$removeKeys3 = array('ID', 'Employee_Number', 'Month', 'Year', 'Company', 'Status', 'payment_cycle', 'Payslip_Number', 'House1', 'closing', 'generated');

foreach($removeKeys3 as $key3) {
   unset($rows4[$key3]);
}

$hr = "PAYE Deductions ";
$pdf->SetXY($x + 65 ,$yt);

$pdf->MultiCell(63, 10, $hr, 3, 1);


$data1 = array();
$y = 47;
foreach($rows4 as $key => $value) {

  if($value > 0) {
    $me =  $key ."\n";
     $pdf->SetXY($x + 65 ,$y);

    $pdf->MultiCell(63, 10, $me, 3, 1);
     $y= $y + 10;  // insert this line
    }

  }

  // value
  $pdf->SetXY(115, $yt9);

  foreach($rows4 as $key => $value) {

  if($value > 0) {
    $me =  number_format($value) . "\n";
    $pdf->SetX(115);
    $pdf->MultiCell(63, 10, $me, 0, 1);
     $y= $y + 10;  // insert this line

    }

  }

  // test 2
    $pdf->SetXY($x_value, $y_value);


$wql = " SELECT * FROM $tbp WHERE Month='$month' AND Year='$year' AND Employee_Number='$user1'";

$hr = "";
$me2 = "";


$pdf->Cell(189, 10, $hr, 3, 1);
$results = mysqli_query($conn, $wql);
$rows1 = mysqli_fetch_assoc($results);

$removeKeys3 = array('ID', 'Employee_Number', 'Month', 'Year', 'Company', 'Status', 'payment_cycle', 'Payslip_Number', 'House1', 'closing', 'generated');

foreach($removeKeys3 as $key3) {
   unset($rows1[$key3]);
}
$data1 = array();
$y = 44;
foreach($rows1 as $key => $value) {

  if($value > 0) {
    $me =  $key . " : " . $value . "\n";

    $pdf->Cell(189, 10, $me2, 3, 1);
     $y= $y + 10;  // insert this line
    }


  }


  //
  $y = 37;
$pdf->SetXY($x + 90 ,$yt);
$col2="Other Deductions   ";
$pql = " SELECT * FROM $tbq WHERE Month='$month' AND Year='$year' AND Employee_Number='$user1'";


$results7 = mysqli_query($conn, $pql);
$rows3 = mysqli_fetch_assoc($results7);
$removeKeys = array('ID', 'Employee_Number', 'Month', 'Year', 'Company', 'Status', 'payment_cycle', 'Payslip_Number', 'House1', 'closing', 'generated');

foreach($removeKeys as $key) {
   unset($rows3[$key]);
}


$pdf->SetXY($x + 130 ,$y);
$pdf->MultiCell(63, 10, $col2, 3,1);
$data2 = array();
$y = 47;
foreach($rows3 as $key => $value) {

  if($value > 0) {
    $me =  $key . "\n";
    $pdf->SetXY($x + 130 ,$y);

    $pdf->MultiCell(63, 10, $me, 3, 1);
     $y= $y + 10;  // insert this line
    }


  }

// value 

$pdf->SetXY(175, $yt9);
foreach($rows3 as $key => $value) {

  if($value > 0) {
    $me = number_format($value) . "\n";
    $pdf->SetX(175);

    $pdf->MultiCell(63, 10, $me, 0, 1);
     $y= $y + 10;  // insert this line
    }


  }
// test

  $me1 = "";
  $pdf->SetXY($x_value, $yt);

$col2="";
$pql = " SELECT * FROM $tbq WHERE Month='$month' AND Year='$year' AND Employee_Number='$user1'";

$results7 = mysqli_query($conn, $pql);
$rows3 = mysqli_fetch_assoc($results7);
$removeKeys = array('ID', 'Employee_Number', 'Month', 'Year', 'Company', 'Status', 'payment_cycle', 'Payslip_Number', 'House1', 'closing', 'generated');

foreach($removeKeys as $key) {
   unset($rows3[$key]);
}


$pdf->Cell(189, 10, $col2, 3,1);
$data2 = array();
$y = 50;
foreach($rows3 as $key => $value) {

  if($value > 0) {
    $me =  $key . " : " . $value . "\n";


    $pdf->Cell(189, 10, $me1, 1, 2);
     $y= $y + 10;  // insert this line
    }


  } 
// end testr


$pdf->SetXY($x + 170 ,$y);

$pdf->MultiCell(63, 10, $col8, 3);


// for the total
$pdf->setY(186);
$pdf->MultiCell(189, 10, $col4, 1, 1);
$pdf->SetX(50);
$pdf->SetY(170);

$pdf->SetX(60);
$pdf->SetY(180);

下面的括号是每行的关闭。应在新的pdf页面上为每个用户显示括号内的所有信息

    }   

$pdf->Output();

?>

0 个答案:

没有答案