php - 使用 Dompdf 的 While 循环输出表

标签 php html mysql dompdf

如何使用 Dompdf 在 while 循环上打印表格以从数据库获取数据?

下面是我已经完成但结果失败的代码。

$html =  '<table>
<tr>
  <td>Date</td><td>Name</td>
</tr>';

// Query from mysql 
if (mysqli_num_rows($result) > 0) {
  while ($row = mysqli_fetch_assoc($result)) {
   $date = $row['date '];
   $name = $row['name'];

   $html . = '<tr>
    <td> ' . $date . ' </td>' . $name . '</td>
   </tr>';
  }
}

$html .= '</table>';

require('../dompdf/autoload.inc.php');
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->load_html($html);

$dompdf->render();
$dompdf->stream("Result.pdf",array("Attachment"=>0));
$dompdf->clear();

最佳答案

<罢工> 1 字符串必须用引号引起来。更改

$html .= </table>

$html .= '</table>';

<罢工>

2 运算符“.=”中不能有空格。改变

$html . = '<tr>

$html .= '<tr>

3最后,“日期”中可能没有空格,所以更改

$date = $row['date '];

$date = $row['date'];

关于php - 使用 Dompdf 的 While 循环输出表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40392837/

相关文章:

php - 如何在 Magento 购物车中使用特殊公式

javascript - PHP 变量中 JavaScript 中的换行符

javascript - 无法使用 JavaScript 使元素返回到其原始状态

javascript - 控制网页中使用的外部 JS 文件的过期时间

html - 如何从网站的 3 个部分制作背景

mysql - 内部连接与联合所有

mysql - 遇到 MySQL 命令 'LOAD DATA INFILE"的问题。我需要将第一行设置为标题

php - 登录codeigniter后在表中添加数据

javascript - PHP json_encode 编码函数

mysql - 呈现 2 个带有 Group By 子句的 select 语句