0

此代码显示一个基本的树结构括号,我正在尝试完成它以现在执行以下操作:-

  1. 它在哪里显示:

    style="border-right:2px solid #000;"

    我正在尝试为每一行使用此边框,但此脚本不会在团队/种子之间创建行来定义边框,我正在尝试为从每个 TEAM 1 到 TEAM 2 等的每一行显示边框右和对于所有其他回合 TEAM 1 到 TEAM 2 等。

  2. PHP 错误报告正在返回以下行,在} ELSE {?之后也有一个未定义的偏移量。

    $line[$i] .= '<td align="center" style="border-right:2px solid #000;" colspan="2">vs</td>';
    

    3.

            $array = array('Team 1', 'Team 2', 'Team 3', 'Team 4', 'Team 5', 'Team 6', 'Team 7', 'Team 8');
            $j = count($array);
            for ($a=0; pow(2, $a) <= $j; $a++) //determine the highest power of 2 that will go into the array count
            {
                $y[$a] = 1;
                $maxpower = $a;
            }
            for ($i=1; $i < $j*2; $i++)
            {
                if($i % 2 != 0) //odd number rows for teams
                {
                    $line[$i] = '<td class="pf_title_bg" style="border-right:2px solid #000;">' . $array[($i-1)/2] . '</td>
                                 <td class="pf_content_bg" style="border-right:2px solid #000;">&nbsp;</td>';
                }
                else
                {
    
                    for($b=0; $b<=$maxpower; $b++)
                    {
    
                        $round = $b+1;              
                        $line2[$b] = ($b < $maxpower ? "<th colspan='2'>Round {$round}</th>" : "<th colspan='2'>Winner</th>");
    
                        if($i % pow(2, $b) == 0) //even rows for future rounds. every 2^1 rows for first winner, 2^2 for second winner, 2^3 for third and so on.
                        {
                            if($i % pow(2, $b+1) != 0) //does not divide by the next power of 2, so this must be the last available cell
                            {
                                $line[$i] .= '<td class="pf_title_bg" style="border-right:2px solid #000;">Team '.$b.'_'.($y[$b]++).'</td>
                                              <td class="pf_content_bg" style="border-right:2px solid #000;">&nbsp;</td>';
                            }
                            else //the input will be added in a future round
                            {
                                $line[$i] .= '<td align="center" style="border-right:2px solid #000;" colspan="2">vs.</td>';
                            }
                        }
                    }
                }
            }   
    
            //name="WIN'.$b.'_'.($y[$b]++).'                
    
            eval ("\$content = \"".$this->gettemplate("table_header")."\";");
    
            $content.="<thead><tr>";
    
            foreach($line2 as $col) 
            {
                $content.=$col;
            }
    
            $content.="</tr></thead>";
    
            foreach($line as $row)
            {
                $content.="<tbody><tr>{$row}</tr></tbody>";
            }
    
            eval ("\$content.= \"".$this->gettemplate("table_footer")."\";");
    

对此非常感谢的任何帮助

4

1 回答 1

0

您没有正确构建表格;您在每一行周围都放置了一个 tbody 标签,从而使您的 HTML 无效。这对我有用:

<?php
$array = array('Team 1', 'Team 2', 'Team 3', 'Team 4', 'Team 5', 'Team 6', 'Team 7', 'Team 8');
            $j = count($array);
            for ($a=0; pow(2, $a) <= $j; $a++) //determine the highest power of 2 that will go into the array count
            {
                $y[$a] = 1;
                $maxpower = $a;
            }
            for ($i=1; $i < $j*2; $i++)
            {
                if($i % 2 != 0) //odd number rows for teams
                {
                    $line[$i] = '<td class="pf_title_bg" style="border-right:2px solid #000;">' . $array[($i-1)/2] . '</td>'.PHP_EOL.'<td class="pf_content_bg" style="border-right:2px solid #000;">&nbsp;</td>'.PHP_EOL;
                }
                else
                {

                    for($b=0; $b<=$maxpower; $b++)
                    {

                        $round = $b+1;
                        $line2[$b] = $b < $maxpower ? "<th colspan='2'>Round {$round}</th>".PHP_EOL : "<th colspan='2'>Winner</th>".PHP_EOL;

                        if($i % pow(2, $b) == 0) //even rows for future rounds. every 2^1 rows for first winner, 2^2 for second winner, 2^3 for third and so on.
                        {
                            if($i % pow(2, $b+1) != 0) //does not divide by the next power of 2, so this must be the last available cell
                            {
                                $line[$i] .= '<td class="pf_title_bg" style="border-right:2px solid #000;">Team '.$b.'_'.($y[$b]++).'</td>'.PHP_EOL.'<td class="pf_content_bg" style="border-right:2px solid #000;">&nbsp;</td>';
                            }
                            else //the input will be added in a future round
                            {
                                $line[$i] .= '<td align="center" style="border-right:2px solid #000;" colspan="2">vs.</td>'.PHP_EOL;
                            }
                        }
                    }
                }
            }

            //name="WIN'.$b.'_'.($y[$b]++).'

            //eval ("\$content = \"".$this->gettemplate("table_header")."\";");

            $content="<table><thead><tr>";

            foreach($line2 as $col)
            {
                $content.=$col;
            }

            $content.="</tr></thead><tbody>".PHP_EOL;

            foreach($line as $row)
            {
                $content.="<tr>{$row}</tr>".PHP_EOL;
            }

            $content.='</tbody></table>';

            //eval ("\$content.= \"".$this->gettemplate("table_footer")."\";");
            echo $content;

?>
于 2013-07-24T20:27:18.847 回答