use PHP to create an HTML table from a MSQL query, without duplicate rows?

后端 未结 1 1980
温柔的废话
温柔的废话 2021-01-24 22:27

I\'m creating a display for a student module webpage that displays in this format

2001/02

  • Computer Science
  • Biology
  • Lorem
1条回答
  •  北恋
    北恋 (楼主)
    2021-01-24 22:57

    I would probably code it like this, probably not the only way but should work based on what I believe you are trying to achieve. Please make sure to add the "order by" to your SQL query as well.

    echo "";
    $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 "
    "; echo ""; $year = ""; while ($row = mysql_fetch_array($result)) { if ($year != $row["ayr"]) { echo ""; $year = $row["ayr"]; } echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
    Module Selection
    " . $row["ayr"] . "
    " . $row["mid"] . "" . $row["mtitle"] . "" . $row["credits"] . "
    ";

    0 讨论(0)
提交回复
热议问题