Dompdf while循环 - 只将最后一条记录转换为pdf

时间:2017-04-20 14:23:16

标签: php dompdf

<?php require"../db_connection1.php";?>
<?php require"../db_connection4.php";?>
<?php require"../db_connection5.php";?>
<?php

require_once('../dompdf/autoload.inc.php') ;
use Dompdf\Dompdf ;
ob_start() ;

if (isset($_POST["submit"])) {  
    $payroll_date    = mysqli_real_escape_string($connection5, $_POST["payroll_date"]) ;
}


$query = "SELECT * FROM  ".$payroll_date."  ";
$result = mysqli_query($connection5, $query);
while ($row1 = mysqli_fetch_array($result)) {   
    $Employee_Number   = $row1[0] ;
}


?>           
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title></title>
  <link href="../bootstrap.min.css" rel="stylesheet">
  <style type="text/css">
    .SECTION-1 { 
      margin-top:110px ;    
      margin-left: 108px ;
      margin-bottom: 5px ;
    }
  </style>
</head> 
<body>
  <form action = "#" method ="POST">
  <div class ="SECTION-1" > 

  <?php

  $query_hr_data = "SELECT * FROM applicants_final WHERE employee_number = '{$Employee_Number}' ";

  $result = mysqli_query($connection4, $query_hr_data );
  while ($row5 = mysqli_fetch_array($result)) {

    $cost_center         =   $row5['cost_center'] ;
    $position            =   $row5['position'] ;

    $query = "SELECT * FROM  ".$payroll_date."  WHERE EE_NUMBER = '{$Employee_Number}' ";
    $result = mysqli_query($connection5, $query);

    while ($row1 = mysqli_fetch_array($result)) {

      $EE_NUMBER         =   $row1['EE_NUMBER'] ;
      $EE_NAME           =   $row1['EE_NAME'] ;

      $query2 = "SELECT * FROM  ".$payroll_date."  WHERE EE_NUMBER = '{$Employee_Number}' ";
      $result = mysqli_query($connection1, $query);

      while ($row2 = mysqli_fetch_array($result)) {

        $LATES_UNDERTIME_HRS   =   $row2['LATES_UNDERTIME'] ;
        $ABSENCES_HRS          =   $row2['ABSENCES'] ;



        echo "<table id ='heading'>" ;

        echo"<tr>" ;
        echo"<th id ='heading-2-1'>EE Name </th>" ;
        echo"<td id ='heading-2'>" .$row1['EE_NAME']." </br> </td>" ;
        echo"<th id ='heading-2-1'>Philhealth # </th>" ;
        echo"<td id ='heading-2'>" .$philhealth_number." </br> </td>" ;
        echo"</tr>" ;

        echo"<tr>" ;
        echo"<th id ='heading-2-1'>Basic_Salary </th>" ;
        echo"<td id ='heading-2'>" .number_format($basic_salary,2). "</br> </td>" ;
        echo"<th id ='heading-2-1'> Allowances </th>" ;
        echo"<td id ='heading-2'>" .number_format($deminimis_benefits,2)."</br> </td>" ;
        echo"</tr>" ;

        echo "</table>" ;
        echo "<table id='design-8'>" ;

        echo"<tr>" ;
        echo"<th>Lates_Undertime ( minutes ) </th>" ;
        echo"<td>" .$LATES_UNDERTIME_HRS. "</br> </td>" ;
        echo"<td>" .$LATES_UNDERTIME." </br> </td>" ;
        echo"</tr>" ;

        echo"<tr>" ;
        echo"<th>Absences </th>" ;
        echo"<td>" .$ABSENCES_HRS." </br> </td>" ;
        echo"<td>" .$ABSENCES." </br> </td>" ;
        echo"</tr>" ;


        echo "</table>" ;
        echo "<div id='design-2'> *** Payslip Confidential *** </div>" ;

  ?>        
  </form>
  </div>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</body>
</html>

    <?php
    $html = ob_get_clean();
    $dompdf = new Dompdf();
    $dompdf->load_html($html);
    $dompdf->setPaper(array(0, 0, 612, 1100), 'portrait');
    $dompdf->render();

    $pdf = $dompdf->output();
    $file_location = "C:/wamp/www/dbs-program/payroll-program/version-3.4/pdfReports/".$Employee_Number.".pdf" ;
    file_put_contents($file_location, $pdf);

    }

  }

}

?>

感谢Brian,我更新了代码,我只是删除了冗余数据  不要太久。再次感谢您再看一遍。

我想打印50加pdf并将其保存到指定的文件夹,其pdf名称为员工编号  mysql数据库。现在问题只是while循环中的最后一个数据  转换为pdf,如果我将第一个查询的结束括号转移到  html之后的最后一个代码,转换的pdf只是第一个。当我  echo $ Employee_Number = $ row1 [0]我得到了所有50多个数据。我已经试过了  像for这样的迭代,但是因为它打印出来变得更复杂  确切的pdf数量,但没有打印数据,希望有人  帮助或提示如何继续。谢谢你。

0 个答案:

没有答案