dompdf - display data from a SQL query

1.1k views Asked by At

How I can display the data in tr depending on the number of characters.

my code is:

<?php
$query = "select text from mytable where id=".$_POST["id"];

$result = mysql_query($query);

$row=mysql_fetch_row($result);    
?>

<table>
<tr class="text-center border">
     <td><?php echo $row[0]; ?></td>
</tr>
<tr class="text-center border">
     <td></td>
</tr>
<tr class="text-center border">
     <td></td>
</tr>
</table>

if the text exceeds I want to show in the other row tr.

1

There are 1 answers

7
MaGnetas On

You might wanna have a look at str_split

<table>
    <?php
        $parts = str_split($row[0], 20);
        foreach ($parts as $part):
    ?>
        <tr class="text-center border">
            <td><?php echo $part; ?></td>
        </tr>
    <?php
        endforeach;
    ?>
</table>

This way you'll just slice your value into as many parts of your desired length (20 chars in my example) as it takes and output them into table rows in a loop.