我有一个 MySQL 表,其中的值包含体育比赛的评委。布局示例:
Table name = competition
panel | name | role
Grade 1 | Bob | Judge 1
Grade 1 | Dave | Judge 2
Grade 2 | Jo | Judge 1
Grade 1 | Kat | Judge 3
我想以以下格式在 HTML 中显示它:
-- Grade 1 --
Judge 1 | Bob
Judge 2 | Dave
Judge 3 | Kat
-- Grade 2 --
Judge 1 | Jo
面板名称是可变的,并且在竞争之间会发生变化,因此不能在代码中使用它们。我的尝试(不起作用)是:
<?php $panels_distinct = mysql_query("SELECT DISTINCT panel FROM competition"); ?>
<table>
<?php while $panel_names = mysql_fetch_array($panels_distinct) { ?>
<tr>
<td colspan="2"><?php echo $panel_names['panel'] ; ?></td>
</tr>
<?php $judges = mysql_query("SELECT * FROM competition WHERE panel = $panel_names['panel'] ") ;
while $judges_info=mysql_fetch_array($judges) { ?>
<tr>
<td><?php echo $judges_info['role'] ; ?></td>
<td><?php echo $judges_info['name'] ; ?></td>
</tr>
<?php } // end while $judges_info ?>
<?php } // end while $panel_names ?>
</table>
目前只输出面板名称。任何帮助或建议都非常感谢!