开发者

PHP/CSS can't get element to sit over a table?

I have a div relatedListings that contains a table of customer's orders.

I want to add a heading above it, I have tried h3, div, and span but it always puts the element below the table.

The code that generates the table:

echo '<div id="relatedListings">
        <h3 id="relatedListingsHeader">Customer\'s Listings</h3>' .
        $account->listAds() .
    '</div>';

The actual source from the browser after executed:

<table id='customerAds'>
    <!-- Generated table data -->
</table><div id="relatedListings">
        <h3 id="relatedListingsHeader">Customer's Listings</h3></div>

Notice in the second snippet, the div is AFTER the table. Any ideas?

EDIT: here is the listAds method:

echo "<table id='customerAds'>
                <tr><th>开发者_运维百科;Ad</th><th>Title</th><th>Description</th><th>Ad Date</th><th>Actions</th></tr>";

        while ($ad = $ads->fetch()) {
            echo "<tr id='row_{$ad['idAds']}'>
                    <td>{$ad['idAds']}</td>
                    <td>{$ad['Title']}</td>
                    <td>" . substr(strip_tags($ad['Description']), 0, 100) . "...</td>
                    <td>" . format::dateConvert($ad['DatePosted'], 12) . "</td>
                    <td><a href='#'>Delete</a></td>
                </tr>";
        }

        echo "</table>";


I would venture to guess that $account->listAds() is echo-ing as well and not returning instead. If you can change that function to return instead you should be better off.

Update: Now having seen your updated code - I'd suggestion having that function return a string - instead of using echo like you are

$tableCode = "<table id='customerAds'>
            <tr><th>Ad</th><th>Title</th><th>Description</th><th>Ad Date</th><th>Actions</th></tr>";

    while ($ad = $ads->fetch()) {
        $tableCode .= "<tr id='row_{$ad['idAds']}'>
                <td>{$ad['idAds']}</td>
                <td>{$ad['Title']}</td>
                <td>" . substr(strip_tags($ad['Description']), 0, 100) . "...</td>
                <td>" . format::dateConvert($ad['DatePosted'], 12) . "</td>
                <td><a href='#'>Delete</a></td>
            </tr>";
    }

    $tableCode .= "</table>";
return $tableCode;


Your generated table data may be malformed, causing the browser to try and fudge the markup into what it thinks you meant. Since you didn't include that markup, I couldn't tell for sure. It would also be helpful to see the code from $account->listAds().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜