简体   繁体   English

dompdf-显示来自SQL查询的数据

[英]dompdf - display data from a SQL query

How I can display the data in tr depending on the number of characters. 如何根据字符数在tr中显示数据。

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. 如果文字超过我想在另一行显示tr。

You might wanna have a look at str_split 您可能想看看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. 这样,您就可以将值切成所需长度的尽可能多的部分(在我的示例中为20个字符),然后将它们循环输出到表行中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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