user1977204
user1977204

Reputation: 234

DOMPDF, brings me an error

This is my code in a PdfHtml class:

public function createTable($result){

    $html = "<html>
                    <body>
                        <table>
                            <th>
                                <td>Descripción</td>
                                <td>Artículo</td>
                                <td>Precio</td>
                            </th>
                        ";
    while($row = mysql_fetch_array($result)){
        $html .= "<tr>";
        $html .= "<td>".$row["producto"]."</td>";
        $html .= "<td>".$row["idProducto"]."</td>";
        $html .= "<td>".$row["precio"]."</td>";
        $html .= "</tr>";
    }

    $html .= "</table>
                </body>
                    </html>";

    return $html;
}
</i>

I'm execute with the following:

$pdfHtml = new PdfHTML();
$result = $pdfHtml->getProductosPorMarca($idMarca);
$html = $pdfHtml->createTable($result);

$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->output();

And throw this:

Catchable fatal error: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, null given, called in /opt/lampp/htdocs/ONLINE/dompdf0.6/include/table_frame_decorator.cls.php on line 304 and defined in /opt/lampp/htdocs/ONLINE/dompdf0.6/include/frame.cls.php on line 726

Please help me, i dont found where is my error!!! Thank you!!

Upvotes: 2

Views: 8937

Answers (3)

Kasun Baththana
Kasun Baththana

Reputation: 11

Use single quotes (' '), like this:

public function createTable($result){
  $html = '<html>
                <body>
                    <table>
                        <th>
                            <td>Descripción</td>
                            <td>Artículo</td>
                            <td>Precio</td>
                        </th>';


  while($row = mysql_fetch_array($result)){
    $html .= "<tr>";
    $html .= "<td>".$row["producto"]."</td>";
    $html .= "<td>".$row["idProducto"]."</td>";
    $html .= "<td>".$row["precio"]."</td>";
    $html .= "</tr>';
  }

  $html .= '</table>
            </body>
            </html>';

  return $html;
}

Upvotes: 0

CodeZero
CodeZero

Reputation: 11

basic < table > elements:

$html = "<html>
                    <body>
                        <table>
                            <tr>
                                <th>Descripción</th>
                                <th>Artículo</th>
                                <th>Precio</th>
                            </tr>
                        ";

Upvotes: 0

BrianS
BrianS

Reputation: 13914

Your HTML is the source of the problem. You have nested a bunch of TD elements inside a TH element, but this is not valid. The container should still be a TR element; the individual cells would then be TH elements. And if you want a table header that repeats across pages you nest the header rows in a THEAD element and the body of the table in a TBODY element.

Upvotes: 7

Related Questions