此代码显示基本树结构括号,我正在尝试完成它,现在执行以下操作: -
它显示的地方:
style =“border-right:2px solid#000;”
我正在尝试为每一行使用此边框,但此脚本不会在团队/种子之间创建行来定义边框,我试图为每个TEAM 1到TEAM的每一行显示border-right 2等,以及所有其他轮次TEAM 1至TEAM 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;"> </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;"> </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")."\";");
对此非常感谢的任何帮助
答案 0 :(得分: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;"> </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;"> </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;
?>