我已经完成了Burak(链接在这里:Limiting number of characters displayed in table cell)已经说过并且工作正常。除了...我的顶部条目不显示数据,我不知道为什么..
以下是我的代码片段:
<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>
答案 0 :(得分:3)
提出这个条件
if (strlen($row['news_body']) > 100) $str = substr($row['news_body'], 0, 100) . "...";
以上
echo '<td style="max-height: 10px;">' . $str . '</td>';
$str
将在while循环中的第一次迭代后设置,这就是第一行为空的原因