我正在为以这种格式显示的学生模块网页创建显示
2001-2002
2002/03
以那种风格 我使用的数据库包含诸如
之类的信息我已经显示了每个模块标题的PHP代码,所以字面上我是一个巨大的模块列表,而我想把它拆分出来就像在那里描述的那样,岁月显示那一年的每个模块。有人帮我吗?代码如下:
<?php
echo "<table cellspacing='40'>";
$query2 ="SELECT mods.mid, ayr, mtitle, credits FROM stud, smod, mods WHERE stud.sid = '".$_POST['stuNo']."' and stud.sid = smod.sid and smod.mid = mods.mid order by ayr ASC";
$result = mysql_query($query2) or die(mysql_error());
echo "Enrolment and progress";
echo "<table width='150' border='1'>";
echo "<th> Module Selection</th>";
echo"<td>".$row["ayr"]."</td>";
while ($row = mysql_fetch_array($result))
{
$temp_year=$row["ayr"];
echo "<tr>";
if ($temp_year!=$row["ayr"]){
echo "<td>" . $row["ayr"] . "</td>";
}
echo "<td>" . $row["mid"] . "</td>";
echo "<td>" . $row["mtitle"] . "</td>";
echo "<td>" . $row["credits"] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
我不知道如何分开它,任何帮助都很棒。谢谢。
答案 0 :(得分:0)
我可能会像这样编码,可能不是唯一的方法,但应该根据我认为你想要实现的目标而工作。请务必按&#34;添加&#34;顺序。也是你的SQL查询。
echo "<table cellspacing='40'>";
$query2 = "SELECT mods.mid, ayr, mtitle, credits FROM stud, smod, mods WHERE stud.sid = '".$_POST['stuNo']."' and stud.sid = smod.sid and smod.mid = mods.mid ORDER BY ayr DESC";
$result = mysql_query($query2) or die(mysql_error());
echo "Enrollment and Progress";
echo "<table width='150' border='1'>";
echo "<tr><td colspan="3"><b>Module Selection</b></td></tr>";
$year = "";
while ($row = mysql_fetch_array($result)) {
if ($year != $row["ayr"]) {
echo "<tr><td colspan="3"><b>" . $row["ayr"] . "</b></td></tr>";
$year = $row["ayr"];
}
echo "<tr>";
echo "<td>" . $row["mid"] . "</td>";
echo "<td>" . $row["mtitle"] . "</td>";
echo "<td>" . $row["credits"] . "</td>";
echo "<tr>";
}
echo "</table>";