简体   繁体   中英

dompdf - display data from a SQL query

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM