在 PHP 中对数据进行排序,以便在 HTML 中显示单场淘汰赛

发布于 2024-12-16 00:12:26 字数 1063 浏览 1 评论 0原文

我有一个包含以下列和字段的表:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦中的蝴蝶 2024-12-23 00:12:26

对于数据表中的每一行,您可以在 HTML 表中找到正确的行以使用以下等式显示它:

rowNum = pow(2, round - 1) + (faceoff - 1) * pow(2, round);

所以这应该适用于 MySQL:

SELECT * FROM tournament ORDER BY pow(2, round - 1) + (faceoff - 1) * pow(2, round);

For each row in your data table, you can find right row in HTML table to display it using this equation:

rowNum = pow(2, round - 1) + (faceoff - 1) * pow(2, round);

so this should work in MySQL:

SELECT * FROM tournament ORDER BY pow(2, round - 1) + (faceoff - 1) * pow(2, round);
青衫负雪 2024-12-23 00:12:26

结构

我使用了 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.

我是男神闪亮亮 2024-12-23 00:12:26

像您拥有的那样按回合对其进行排序,并在循环浏览行时跟踪当前回合。如果该行的轮次不等于当前轮次,您就知道要向右移动。您可以关闭并启动 divul 并将它们浮动到左侧。

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 or ul and float them to the left.

http://jsfiddle.net/RxDrd/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文