我创建了一个从数据库 mysql 获取数据的 dompdf。但我的问题是,如果每个用户的数据将超过 19 个事务,我将如何迭代页面?
<?php
define( 'WP_USE_THEMES', false );
define( 'COOKIE_DOMAIN', false );
define( 'DISABLE_WP_CRON', true );
require('wp-load.php');
global $current_user;
get_currentuserinfo();
$d = $current_user->user_login;
// include autoloader
require_once 'dompdf/autoload.inc.php';
// reference the Dompdf namespace
use Dompdf\Dompdf;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$html = '<html><body>'.
'<p>Date | Details </p>';
$ff = $wpdb->get_results( "SELECT * FROM table WHERE dd = '$d' ORDER by tdate");
foreach ( $ff as $jj ) {
$html = '<p>'.$jj->tdate.' | '.$jj->details.'</p>';
}
$html .= ''</body></html>';
$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
//$dompdf->stream();
// Output the generated PDF (1 = download and 0 = preview)
$dompdf->stream("codex",array("Attachment"=>0));
目前它仅适用于 1 页,但我的问题是当每个用户的数据超过 19 到更高的事务时,它会破坏页面。我想设置每页 19 个事务。
BTW 示例输出如下所示:
这里有人能帮帮我吗?
谢谢。
最佳答案
试试这个
$start = '<html><body>';
$body = '<p>Date | Details </p>';
$ff = $wpdb->get_results( "SELECT * FROM table WHERE dd = '$d' ORDER by tdate");
foreach ( $ff as $jj ) {
$body .= '<p>'.$jj->tdate.' | '.$jj->details.'</p>';
}
$end= '</body></html>';
$dompdf->loadHtml($start.$body.$body.$end);
在您的代码中实现此代码。
关于php - 如何在dompdf中创建多个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41477100/