How to capture code from a table generated via html?

Asked

Viewed 124 times

1

I generated a table with data by HTML and PHP, how do I generate a string of this table with this data so I can play in my DOMPDF load_html?

  • It may seem kind of obvious, but did you at the time of the generation try to create a variable and throw the code in? I use this way to generate a table and send by email: $variable = '<html>..... </html>';

  • It’s because I generated my data through a while in php. I want to get this table already with the data fed

  • Inside while creates a variable by cloning the table. You can concatenate it using $variable .=

  • Could post the code in which you generate the table?

1 answer

0

Suppose your table after the while has been generated with the following structure:

<table>
    <tr>
        <td>
            bla
        </td>
        <td>
            ble
        </td>
    </tr>
    <tr>
        <td>
            bli
        </td>
        <td>
            blo
        </td>
    </tr>
</table>

When the while is running, we can generate a variable with the table rows as follows

    while($row = $result->fetch_array()){
     $dados1 = $row["dados1"];
     $dados2 = $row["dados2"];
     $dados3 = $row["dados3"];
     $dados4 = $row["dados4"];
     $strLinhas = "<tr><td>".$dados1."</td><td>".$dados2."</td></tr><tr><td>".$dados3."</td><td>".$dados4."</td></tr>";
}

and after the while to be executed concatenate the result in the variable below

$strTabela = "<table>".$strLinhas."</table>";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.