下面是我的查询:
找到了这个问题感谢Mark Bannister尝试MYSQL工作台。它不再显示一行,而是显示所需的行,在下面:
Course: INFO101 - Bsc Information Communication Technology Year: 3
Student: Mayur Patel (u0867587)
Module: CHI2550 - Modern Database Applications
Session: AAB 72 (A)
Course: INFO101 - Bsc Information Communication Technology Year: 3
Student: Mayur Patel (u0867587)
Module: CHI2513 - Systems Strategy
Session: AAD 61 (B)
Course: INFO101 - Bsc Information Communication Technology Year: 3
Student: Mayur Patel (u0867587)
Module: CHI2550 - Modern Database Applications
Session: AAE 67 (B)
所以我现在需要帮助的是如何使用php显示它,使它只显示一次课程详细信息和学生详细信息,它将显示课程中的每个模块只显示一次并且显示每个会话位于它所属的每个模块之下:
上面的输出应该是这样的,换句话说: Course: INFO101 - Bsc Information Communication Technology Year: 3
Student: Mayur Patel (u0867587)
Module: CHI2550 - Modern Database Applications
Session: AAB 72 (A)
Session: AAE 67 (B)
Module: CHI2513 - Systems Strategy
Session: AAD 61 (B)
PHP代码输出结果:
$output1 = "";
while ($row = mysql_fetch_array($result)) { //$result is the query
$output1 .= "
<p><strong>Course:</strong> {$row['CourseId']} - {$row['CourseName']} <strong>Year:</strong> {$row['Year']}<br/>
<strong>Student:</strong> {$row['StudentForename']} {$row['StudentSurname']} ({$row['StudentUsername']})
</p>";
$output1 .= "
<p><strong>Module:</strong> {$row['ModuleId']} - {$row['ModuleName']} <br/>
<strong>Session:</strong> {$row['SessionId']} {$row['Mark']} ({$row['Grade']})
</p>";
}
echo $output1;
谢谢
我想你已经用sql语句
排序你的结果集升序ORDER BY `CourseName` ASC
所以,问题是你的结果集的第一行:学士学位信息通信技术原因是您已经对结果集执行了一些操作。转到while前的第一行:
//do this before anything:
mysql_data_seek($result, 0);
//now, you are at first row
$output1 = "";
while ($row = mysql_fetch_array($result)) { //$result is the query
$output1 .= "
<p><strong>Course:</strong> {$row['CourseId']} - {$row['CourseName']} <strong>
Year:</strong> {$row['Year']}<br/><strong>Student:</strong>
{$row['StudentForename']} {$row['StudentSurname']} ({$row['StudentUsername']})
</p>";
$output1 .= "
<p><strong>Module:</strong> {$row['ModuleId']} - {$row['ModuleName']} <br/>
<strong>Session:</strong> {$row['SessionId']} {$row['Mark']} ({$row['Grade']})
</p>";
}
echo $output1;
忽略我的换行符