Blood_Wolf89
Blood_Wolf89

Reputation: 45

Limit Chars displayed in table issue

I have done what Burak (Linked Here: Limiting number of characters displayed in table cell ) has said and it works fine. EXCEPT... my top entry does not display the data and I don't know why..

Here is a snippet of my code:

<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>

Upvotes: 1

Views: 311

Answers (1)

Mihai
Mihai

Reputation: 26784

Put this condition

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

above

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

$str will be set after the first iteration in the while loop that`s why the first row is empty

Upvotes: 3

Related Questions