dssu33392 2013-01-04 15:06
浏览 50
已采纳

使用mPDF从数据库调用行

I just try mPDF to make an output table pdf by database, but it still hard to do that.

<?php
$html = '

<center><h3>TITLE</h3></center>
<center>
<table border="1">
<tr>
    <th>COLUMN 1</th><th>COLUMN 2</th>
</tr>
<tr>
        <!--how to fetch this row from DB? -->
    <td>.$row[no1].</td><td>.$row[no2].</td>
</tr>
</table></center>

';
//==============================================================
//==============================================================
//==============================================================
include("../mpdf.php");
    include "conn.php";

    $res = mysql_query("select * from list");
    if (!$res)
        die("query error : ".mysql_error());
$mpdf=new mPDF('c','A4','','',32,25,27,25,16,13);
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list
// LOAD a stylesheet
$stylesheet = file_get_contents('mpdfstyletables.css');
$mpdf->WriteHTML($stylesheet,1); // The parameter 1 tells that this is css/style only and no body/html/text
while($row = mysql_fetch_array($res))
    if (!$res)
        die("error fetch array : ".mysql_error());
$mpdf->WriteHTML($html,2);
$mpdf->Output('mpdf.pdf','I');
exit;
//==============================================================
//==============================================================
//==============================================================
?>

when I run this script, it can generate to PDF but the row didn't match like the database?

  • 写回答

1条回答 默认 最新

  • dssjxvbv918586 2013-01-04 15:41
    关注

    something like this :

    <?php
    
    //==============================================================
    //==============================================================
    //==============================================================
    include("../mpdf.php");
    include "conn.php";
    
    $res = mysql_query("select * from list");
    if (!$res)
        die("query error : ".mysql_error());
    $mpdf=new mPDF('c','A4','','',32,25,27,25,16,13);
    $mpdf->SetDisplayMode('fullpage');
    $mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list
    // LOAD a stylesheet
    $stylesheet = file_get_contents('mpdfstyletables.css');
    $mpdf->WriteHTML($stylesheet,1); // The parameter 1 tells that this is css/style only and no body/html/text
    $html = '
    
    <center><h3>TITLE</h3></center>
    <center>
    <table border="1">
    <tr>
    <th>COLUMN 1</th><th>COLUMN 2</th>
    </tr>
    <tr>';
    
    while($row = mysql_fetch_array($res)){
    $html .= '<td>'.$row['no1'].'</td><td>' . $row['no2']. '</td>';
    }
    $html .= '</tr>
    </table></center>
    ';
    $mpdf->WriteHTML($html,2); 
    $mpdf->Output('mpdf.pdf','I');
    exit;
    //==============================================================
    //==============================================================
    //==============================================================
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题