在 PHP 中对数据进行排序,以便在 HTML 中显示单场淘汰赛
我有一个包含以下列和字段的表:
userid round faceoff username
------------------------------
1 1 2 Kevin
3 1 1 Steve
4 1 3 Jake
9 1 4 Sam
1 2 1 Kevin
9 2 2 Sam
1 3 1 Kevin
圆形是列,对角是行。因此,第 1 轮的最大对峙数为 4,第 2 轮的最大对峙数为 2,等等。
我想在用户屏幕上显示数据,如下所示(基本 HTML):
Round 1 Round 2 Final (round 3)
Steve
Kevin
Kevin
Kevin
Jake
Sam
Sam
这是我目前所拥有的:
$ tor
是来自 MySQL 的数组,我 var_dump()
它,一切都在那里。我只是遇到了 for
循环的问题:
for ($u=0;$u<=$torindex;$u++)
{
for ($r=1;$r<=$torindex+1;$r++)
{
if ($tor[$u]['round'] == $r)
{
for ($f=1;$f<=$torindex+1;$f++)
{
if ($tor[$u]['faceoff'] == $f) $placement[$r][$f] = $tor[$u]['userid'].":".$tor[$u]['username'];
}
}
}
}
我该去哪里?
I have a table that has the following columns and fields:
userid round faceoff username
------------------------------
1 1 2 Kevin
3 1 1 Steve
4 1 3 Jake
9 1 4 Sam
1 2 1 Kevin
9 2 2 Sam
1 3 1 Kevin
The round are the columns and faceoff are the rows. Thus round 1 has a max of faceoff 4, and round 2 has a faceoff max of 2, etc.
I want to display the data on users screens like so (basic HTML):
Round 1 Round 2 Final (round 3)
Steve
Kevin
Kevin
Kevin
Jake
Sam
Sam
Here is what I have so far:
$tor
is the array from MySQL, I var_dump()
it and everything is there. I'm just having issues with the for
loops:
for ($u=0;$u<=$torindex;$u++)
{
for ($r=1;$r<=$torindex+1;$r++)
{
if ($tor[$u]['round'] == $r)
{
for ($f=1;$f<=$torindex+1;$f++)
{
if ($tor[$u]['faceoff'] == $f) $placement[$r][$f] = $tor[$u]['userid'].":".$tor[$u]['username'];
}
}
}
}
Where do I go from here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于数据表中的每一行,您可以在 HTML 表中找到正确的行以使用以下等式显示它:
所以这应该适用于 MySQL:
For each row in your data table, you can find right row in HTML table to display it using this equation:
so this should work in MySQL:
结构
我使用了 Knockout 锦标赛调度程序 类尼古拉斯·莫索尔·拉斯曼 (Nicholas Mossor Rathmann) 过去在这项任务中取得了巨大成功。给定球队/球员,它将根据比赛的最终得分计算平局和淘汰赛。
输出
对于 CSS/HTML 输出而不是 GD 生成的图像,该类为您提供了我使用 One Fork 的 jQuery &用于绘制单淘汰赛括号的 JSON,并进行了一些针对 IE 兼容性的修改。
Structure
I have used the Knockout tournament scheduler class by Nicholas Mossor Rathmann for this task in the past with great success. Given teams/players it will calculate the ties and eliminations based on the matches final score.
Output
For CSS/HTML output instead of the GD generated image the class gives you I used One Fork's jQuery & JSON to draw single-elimination tournament bracket with some modifications for IE compatibility.
像您拥有的那样按回合对其进行排序,并在循环浏览行时跟踪当前回合。如果该行的轮次不等于当前轮次,您就知道要向右移动。您可以关闭并启动
div
或ul
并将它们浮动到左侧。http://jsfiddle.net/RxDrd/
Sort it by round like you have it and as you cycle through the rows keep track of the current round. If the row's round is not equal to the current round you know to move to the right. You can close and start a
div
orul
and float them to the left.http://jsfiddle.net/RxDrd/