我用PHP编写代码(如下所列),但面临一个小问题......
<html>
<head>
<title> trans </title>
<body>
<style>
table, th, td {
border: 1px solid black;
width: 700px;
margin: auto;
}
</style>
<?php
$con = mysqli_connect('localhost', 'root', '');
if(!$con)
{
die("not ok");
}
mysqli_select_db($con,"uoh");
$q1 = "SELECT * FROM student_record INNER JOIN degree_plan ON
student_record.course_number = degree_plan.course_number
INNER JOIN courses ON student_record.course_number =
courses.course_number where student_record.id = 201102887 AND degree_plan.major='COE'";
$result = mysqli_query($con , $q1 ) ;
if($result){
echo "<table>";
echo "<tr>";
echo "<th>courses</th>";
echo "<th>terms</th>";
echo "<th>grades</th>";
echo "<th>CRD</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row["code"]. "</td>";
echo "<td>" . $row["term_no"]. "</td>";
echo "<td>" . $row["grade"]. "</td>";
echo "</tr>";
}
echo "</table>";
}
?>
</body>
</html>
当我运行代码时,我看到以下输出:
---------------------------------------
| courses | terms | grades |
---------------------------------------
| CHEM 101 | 1 | A |
---------------------------------------
| ENGL 101 | 1 | C+ |
---------------------------------------
| PE 101 | 1 | B |
---------------------------------------
| PHYS 101 | 1 | F |
---------------------------------------
| ENGL 102 | 2 | B+ |
---------------------------------------
| PE 101 | 2 | B |
---------------------------------------
| PHYS 102 | 2 | D+ |
---------------------------------------
| MATH 201 | 3 | A |
---------------------------------------
| COE 200 | 3 | B |
---------------------------------------
但我不想那样。我希望术语细胞成为一体,如下所示:
---------------------------------------
| courses | term | grade |
---------------------------------------
| CHEM 101 1 A |
| ENGL 101 C+ |
| PE 101 B |
| PHYS 101 F |
---------------------------------------
| ENGL 102 2 B+ |
| PE 101 B |
| PHYS 102 D+ |
---------------------------------------
| MATH 201 3 A |
| COE 200 B |
---------------------------------------
或以任何其他方式不允许术语重复,我的意思是:将具有相同术语的课程组合在一起。
答案 0 :(得分:0)
试试这段代码,
function test ($id)
{
echo $id ."<br>";
echo $this->input->post('name');
}