需要按字母顺序垂直打印 5 列列表
拥有一个主要由 IE 用户查看的网页,因此 CSS3 是不可能的。
我希望它的列表如下:
A D G
B E H
C F I
这是当前列出的函数:
A B C
D E F
G H I
function listPhoneExtensions($group,$group_title) {
$adldap = new adLDAP();
$group_membership = $adldap->group_members(strtoupper($group),FALSE);
sort($group_membership);
print "
<a name=\"".strtolower($group_title)."\"></a>
<h2>".$group_title."</h2>
<ul class=\"phone-extensions\">";
foreach ($group_membership as $i => $username) {
$userinfo = $adldap->user_info($username, array("givenname","sn","telephonenumber"));
$displayname = "<span class=\"name\">".substr($userinfo[0]["sn"][0],0,9).", ".substr($userinfo[0]["givenname"][0],0,9)."</span><span class=\"ext\">".$userinfo[0]["telephonenumber"][0]."</span>";
if($userinfo[0]["sn"][0] != "" && $userinfo[0]["givenname"][0] != "" && $userinfo[0]["telephonenumber"][0] != "") {
print "<li>".$displayname."</li>";
}
}
print "</ul><p class=\"clear-both\"><a href=\"#top\" class=\"link-to-top\">↑ top</a></p>";
}
渲染的 html 示例:
<ul class="phone-extensions">
<li><span class="name">Barry Bonds</span><span class="ext">8281</span></li>
<li><span class="name">Gerald Clark</span><span class="ext">8211</span></li>
<li><span class="name">Juan Dixon</span><span class="ext">8282</span></li>
<li><span class="name">Omar Ebbs</span><span class="ext">8252</span></li>
<li><span class="name">Freddie Flank</span><span class="ext">2281</span></li>
<li><span class="name">Jerry Gilmore</span><span class="ext">4231</span></li>
<li><span class="name">Kim Moore</span><span class="ext">5767</span></li>
<li><span class="name">Barry Bonds</span><span class="ext">8281</span></li>
<li><span class="name">Gerald Clark</span><span class="ext">8211</span></li>
<li><span class="name">Juan Dixon</span><span class="ext">8282</span></li>
<li><span class="name">Omar Ebbs</span><span class="ext">8252</span></li>
<li><span class="name">Freddie Flank</span><span class="ext">2281</span></li>
<li><span class="name">Jerry Gilmore</span><span class="ext">4231</span></li>
<li><span class="name">Kim Moore</span><span class="ext">5767</span></li>
<li><span class="name">Barry Bonds</span><span class="ext">8281</span></li>
<li><span class="name">Gerald Clark</span><span class="ext">8211</span></li>
<li><span class="name">Juan Dixon</span><span class="ext">8282</span></li>
<li><span class="name">Omar Ebbs</span><span class="ext">8252</span></li>
<li><span class="name">Freddie Flank</span><span class="ext">2281</span></li>
<li><span class="name">Jerry Gilmore</span><span class="ext">4231</span></li>
<li><span class="name">Kim Moore</span><span class="ext">5767</span></li>
</ul>
任何帮助都可以使其垂直列出 alpha。
Have a webpage that will be viewed by mainly IE users, so CSS3 is out of the question.
I want it to list like:
A D G
B E H
C F I
Here is the function that currently lists like:
A B C
D E F
G H I
function listPhoneExtensions($group,$group_title) {
$adldap = new adLDAP();
$group_membership = $adldap->group_members(strtoupper($group),FALSE);
sort($group_membership);
print "
<a name=\"".strtolower($group_title)."\"></a>
<h2>".$group_title."</h2>
<ul class=\"phone-extensions\">";
foreach ($group_membership as $i => $username) {
$userinfo = $adldap->user_info($username, array("givenname","sn","telephonenumber"));
$displayname = "<span class=\"name\">".substr($userinfo[0]["sn"][0],0,9).", ".substr($userinfo[0]["givenname"][0],0,9)."</span><span class=\"ext\">".$userinfo[0]["telephonenumber"][0]."</span>";
if($userinfo[0]["sn"][0] != "" && $userinfo[0]["givenname"][0] != "" && $userinfo[0]["telephonenumber"][0] != "") {
print "<li>".$displayname."</li>";
}
}
print "</ul><p class=\"clear-both\"><a href=\"#top\" class=\"link-to-top\">↑ top</a></p>";
}
Example rendered html:
<ul class="phone-extensions">
<li><span class="name">Barry Bonds</span><span class="ext">8281</span></li>
<li><span class="name">Gerald Clark</span><span class="ext">8211</span></li>
<li><span class="name">Juan Dixon</span><span class="ext">8282</span></li>
<li><span class="name">Omar Ebbs</span><span class="ext">8252</span></li>
<li><span class="name">Freddie Flank</span><span class="ext">2281</span></li>
<li><span class="name">Jerry Gilmore</span><span class="ext">4231</span></li>
<li><span class="name">Kim Moore</span><span class="ext">5767</span></li>
<li><span class="name">Barry Bonds</span><span class="ext">8281</span></li>
<li><span class="name">Gerald Clark</span><span class="ext">8211</span></li>
<li><span class="name">Juan Dixon</span><span class="ext">8282</span></li>
<li><span class="name">Omar Ebbs</span><span class="ext">8252</span></li>
<li><span class="name">Freddie Flank</span><span class="ext">2281</span></li>
<li><span class="name">Jerry Gilmore</span><span class="ext">4231</span></li>
<li><span class="name">Kim Moore</span><span class="ext">5767</span></li>
<li><span class="name">Barry Bonds</span><span class="ext">8281</span></li>
<li><span class="name">Gerald Clark</span><span class="ext">8211</span></li>
<li><span class="name">Juan Dixon</span><span class="ext">8282</span></li>
<li><span class="name">Omar Ebbs</span><span class="ext">8252</span></li>
<li><span class="name">Freddie Flank</span><span class="ext">2281</span></li>
<li><span class="name">Jerry Gilmore</span><span class="ext">4231</span></li>
<li><span class="name">Kim Moore</span><span class="ext">5767</span></li>
</ul>
Any help is appreciated to getting it to list alpha vertically.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会将关键数据加载到一个数组中,以便您可以对它们进行计数并按您想要的任何顺序逐步执行它们。然后使用这样的算法让它们按正确的顺序排列:
我认为这应该可行,但我还没有测试过。
I would load the critical data into an array so you can count them and step through them in whatever order you want. Then use an algorithm like this to get them in the right order:
I think that should work, but I haven't tested it.
我发布对这个老问题的答案是出于以下原因:
实际上,我想出的解决方案非常简单——在一个巨大的表格内使用多个带有 style="float:left" 的标签。虽然我怀疑在单个表中包含多个 tbody 标记能否通过 HTML 验证,但实际上它确实通过了,没有错误。
请注意,以下
。
这是我的完整答案:
我希望这个答案有一天对您有用。
I am posting my answer to this old question for the following reasons:
Actually, the solution I came up with was pretty simple--use multiple tags with style="float:left", inside of a giant table. While I was sceptical that having multiple tbody tags in a single table would pass HTML validation, it in fact did pass without errors.
Note the following
Here's my full answer:
I hope that this answer is useful to you someday.
标题显示 5 列,但您的示例显示 3 列。我假设 3。
将数据存储在数组中并对它们进行排序后,执行以下操作:
对于 3 列,您希望位置 0,3,6 位于同一行。下一行的每个值都会增加 1。所以,1,4,7。下一行将是 2、5、8。
因此,您可以将 for 循环更改为最初保存 3 个值。 0,3,6,然后递增每个,并创建下一行。
The title states 5 columns, but your example shows 3. I'll assume 3.
After storing your data in an array, and sorting them, do the following:
For 3 columns, you want position 0,3,6 on the same row. The next row will have increments of 1 of each of those values. So, 1,4,7. The next row will be 2,5,8.
Therefore, you can change your for loop to hold 3 values initially. 0,3,6, and then increment each, and create the next row.
这对我有用。请注意,在我标记的行(//添加行)上发现行计数后,列将根据行计数进行重置。您可以看到我正在使用 screenWidth 和 itemWidth 来计算列数。
当空项数大于行数时就会出现问题。如果我有 8 列和 17 条记录,我会得到 3 行(Ceiling(17 / 8) = 3)。这是一个问题 (3 * 8) - 17 = 7 条空记录。发生的情况是这样的:
由于行数为 3,所以我添加的代码行修复了一些问题:
columnCount = 17 / 3 Ceiling = 6(columns),因此我的布局呈现如下(我的客户计算出宽度)。
希望这对遇到我的问题的人有所帮助。
Here is what worked for me. Note that the columns are reset based on the rowCount after it is discovered on the line I labeled(// Added line). You can see I am using a screenWidth and itemWidth to compute my number of columns.
A problem occurs when the number of empty items is greater than the number of rows. If I have 8 columns and 17 records I get 3 rows(Ceiling(17 / 8) = 3). This is a problem (3 * 8) - 17 = 7 empty records. And this is what happens:
Since rows are 3 then the line of code that I added fixes things:
columnCount = 17 / 3 Ceiling = 6(columns) so my layout renders as follows (my client works out the widths).
Hopefully that helps out anyone who was facing my issue.