Php 将结果提取到 table

Php Fetch Results into the table

下面是我的代码,但是,我没有得到我期望的 table。而不是第一行似乎没问题,其他行没有出现在 table 中。请参考照片。

    $Sql = "SELECT Registration_Number,Name FROM vta";
    
    $Result = $conn->Query($Sql);
    
    
    if ($Result -> num_rows> 0) {    
        echo "<table border=2> 
            <tr><th>Registration_Number</th>
            <th>Name</th></tr>";
    
        while ($Row = $Result->fetch_assoc()) {
            // $Rm=$Row['Registration_Number'];
            // $Nm = $Row['Name'];
    
            echo "<tr><td>$Row[Registration_Number]</td><td>$Row[Name]</td></tr></table>";
        }
    }
    
    $conn->Close();

enter image description here

您必须将关闭 </table> 移到循环之外。

$Sql = "SELECT Registration_Number,Name FROM vta";

$Result = $conn->Query($Sql);


if($Result->num_rows > 0) {
    echo "<table border=2> 
        <tr><th>Registration_Number</th>
        <th>Name</th></tr>";

    while ($Row = $Result->fetch_assoc()){
        echo "<tr><td>$Row['Registration_Number']</td><td>$Row['Name']</td></tr>";
    }

    echo '</table>';
}

$conn->Close();