0

while我有一个从PHP 编码的循环中获取的名称列表。当我尝试显示嵌入在 div 中的循环内容时,内容会重叠。我用于内容的样式是:

<style>
    #cap{
        position: absolute;
        top: 0px;
        right: 0px;
    }
</style>

以下是循环内容的完整代码以及 PHP 中 div 的样式:

<?php
    $result2 = mysql_query("SELECT `player_name` FROM `player_data` WHERE  `team_id`=$team2");

    while($row = mysql_fetch_assoc($result2))
    {
        $name2 = $row['player_name'];
        echo "<div id='cap'>";
        echo "" . $name2 . "<br/>";
        echo "</div>";
    }
?>

如何使此内容 $name2 不重叠?

4

2 回答 2

0

像这样的东西:

echo '<div id="cap">';
while($row = mysql_fetch_assoc($result2))
{
    $name2 = $row['player_name'];
    echo '<div class="player">';
    echo $name2;
    echo '</div>';
}
echo '</div>';
于 2013-04-15T07:29:17.033 回答
0

将带有该 CSS 的 div 放在循环之外:

echo '<div id="cap">';
while($row = mysql_fetch_assoc($result2))
{
     $name2 = $row['player_name'];
     echo "" . $name2 . "<br/>";
}
echo "</div>";
于 2013-04-15T07:37:02.043 回答