Reputation: 657
How to print a table on while loop to get data from database using Dompdf?
Below are my codes that I have done but with fail result.
$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();
Upvotes: 0
Views: 1986
Reputation: 6591
1 The string must be quoted. Change
$html .= </table>
to
$html .= '</table>';
2 The operator ".=" must not have a space in it. Change
$html . = '<tr>
to
$html .= '<tr>
3 Finally, there is probably not a space in the "date", so Change
$date = $row['date '];
to
$date = $row['date'];
Upvotes: 2