【问题标题】:Limit Chars displayed in table issue限制在表格问题中显示的字符
【发布时间】:2014-07-04 17:04:32
【问题描述】:

我已经完成了 Burak(此处链接:Limiting number of characters displayed in table cell)所说的,并且效果很好。除了...我的顶部条目没有显示数据,我不知道为什么..

这是我的代码的 sn-p:

<form id="mainform" action="">
        <table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
        <tr>
            <th class="table-header-repeat line-left minwidth-1"><a href="">Title</a>   </th>
            <th class="table-header-repeat line-left minwidth-1"><a href="">Content</a></th>
            <th class="table-header-repeat line-left" width="100px"><a href="">Date Posted</a></th>
            <th class="table-header-options line-left"><a href="">Options</a></th>
        </tr>
        <tr>
            <?php 

            $result = mysqli_query($con,"SELECT * FROM content ORDER BY news_date ASC");

            while($row = mysqli_fetch_array($result))
                {
                 echo '<tr>';
                 echo '<td>' . $row['news_title'] . '</td>';
                 echo '<td style="max-height: 10px;">' . $str . '</td>';
                 echo '<td width="100px">' . $row['news_date'] . '</td>';
                 echo '<td class="options-width">';
                 echo '<a href="includes/edit_content.php?=' . $row['news_id'] . '" id="Edit" class="icon-1 info-tooltip"></a>';
                 echo '<a href="includes/delete_content.php?news_id=' . $row['news_id'] . '" name="delete" id="delete" class="icon-2 info-tooltip"></a></td>';
                 echo '</tr>';

                if (strlen($row['news_body']) > 100) $str = substr($row['news_body'], 0, 100) . "...";  


            }

            ?>
            <br />
            <br />
            </form>

【问题讨论】:

  • 你有一个未闭合的 上面的 php 标签。
  • 刚刚修复它,谢谢.. 我仍然遇到顶行没有显示“news_body”但标题、日期、选项仍然显示所有行的问题

标签: php sql html-table strlen


【解决方案1】:

提出这个条件

if (strlen($row['news_body']) > 100) $str = substr($row['news_body'], 0, 100) . "..."; 

上面

 echo '<td style="max-height: 10px;">' . $str . '</td>';

$str 将在 while 循环的第一次迭代后设置,这就是第一行为空的原因

【讨论】:

  • 哇,非常感谢!对我来说这是多么愚蠢的错误!我会 +1 你,但我没有足够的代表。再次,谢谢你!一旦我再获得2个代表。我会为此 +1!
猜你喜欢
相关资源
最近更新 更多
热门标签