我已经尝试了很多方法来让这张桌子打印得尽可能好,但我失败了。我知道这很简单,所以我希望你能帮助我。
这是我的代码:
<?php
include('../connect.php');
$id=$_SESSION['login_user'];
$sql = "Select CourseName , Studentname from course p natural join student t";
$rs_result = mysql_query ($sql, $connection);
echo "<center>";
echo "<table>";
echo "<tr> <th>Course Name</th> <th> Students Name</th> </tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $rs_result )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['CourseName'] . '</td>';
echo "<td rowspan=''> $row[Studentname] </td> ";
echo "</tr>";
}
echo "</table>";
echo "</center>";
?>
我想成为这样的人
Course | Name | Student name |
Math101 | john, Mike |
...
另外,两个表之间的 JOIN 查询是否正确?
这两个表是:
Course ( Course name - Course id )
Student ( Student name - Course id )