从 PHP 中的表格记录生成 PDF


generate pdf from tabulated records in php

我想从下面的代码生成pdf文件,我的代码返回员工佣金报告。我想以pdf格式显示该记录。我正在使用phptopdf API

我可以生成它,但中间我有 while 循环,所以我不能将我想要的格式存储在结构内带有 php 代码的变量中。

<table id="example1" class="table table-bordered table-striped">
                           <thead>
                           <tr>
                           <th>Date</th>
                           <th>Employee Name</th>
                           <th>Employee Code</th>
                           <th>Commission Amount</th>
                           </tr>
                           </thead>
                <?php   
                if(isset($_POST['submit']))
                {  
                  extract($_POST);
                  $con='';
                  if($fromdate!='' && $todate!=''){ $con .="AND `credit_date` BETWEEN '$fromdate' AND '$todate'";}
                  else{ $con .="";}
                 $agent_commissions="SELECT * FROM commission_details WHERE `emp_code`='".$emp_code."'".$con;
                 //echo $agent_commissions."<br>";
                 $get_all=mysql_query($agent_commissions);
                 $row_count=mysql_num_rows($get_all);
                 if($row_count == 0){echo "<h3 class='msyqlerror'>No records found<h3>";exit(0);}
                 $total_amnt="";
                     while($rows=mysql_fetch_array($get_all))
                     {
                        // echo $rows['comm_amount']."<br>";
                         $total_amnt = $total_amnt+$rows['comm_amount'];
                ?>

请帮我解决这个问题:(

                <td><?php echo $rows['credit_date'];?></td>
                <td>
                    <?php
                      $get_name="SELECT e1.emp_name,e1.emp_code,c1.emp_code FROM emp_details e1,commission_details c1 WHERE e1.emp_code = '".$emp_code."'";
                     // echo $get_name;
                      $exe_name=mysql_query($get_name);
                      $name_fetch=mysql_fetch_array($exe_name);
                      echo $name_fetch['emp_name'];
                    ?>
                </td>
                <td><?php echo $rows['emp_code'];?></td>
                <td><?php echo $rows['comm_amount'];?></td>
                <?php 
                    }?>
                    <tr>
                      <td colspan=3 align="right">Total</td>
                      <td> <?php  echo $total_amnt;
                }
                ?></td>
                    </tr>
             </tbody>
    </table>

这是一个教程,将为您提供有关PDF的简要说明,

http://www.code2learn.com/2012/03/generating-tabulated-pdf-file-from.html

我没有使用过phptopdf API,但我认为您可以将所有日期存储在变量中,然后将该变量传递给pdf函数。