我在html页面上写了一个可用玩家列表 - 但是我的列表差不多有65个玩家。 我使用以下css
拆分html页面#right_side {
float: right;
margin: 20px 0px 20px 0px;
width: 500px;
height: 675px;
border: 1px solid #CCCCCC;
font-family: italic;
}
PHP代码以下列方式遍历列表:
while($row = mysql_fetch_array($result)){
echo "<li>".$row['FirstName'] . " " . $row['LastName']."</li>";
echo"<br>";
}
如何分解结果,使它们分成3列,而不是60列的一列?
答案 0 :(得分:0)
添加以下css
li
{
display:inline-block;
width:30%;
}
这会给你
1 | 2 | 3
4 | 5 | 6
等
请在此处查看:http://jsfiddle.net/cmw7T/
答案 1 :(得分:0)
尝试这个
PHP
$total_num_each_column = mysql_num_rows($result) / 3;
$count = 0;
echo "<ul id='box'>";
while($row = mysql_fetch_array($result)){
if($count > $total_num_each_column) {
echo "</ul> <ul id='box'>";
}
echo "<li>".$row['FirstName'] . " " . $row['LastName']."</li>";
if($count > $total_num_each_column) {
echo "</ul>";
}
$count++;
}
CSS
#box {
float:left;
margin-left:10px;
}
我希望它有所帮助。