PHP一直出现在页面底部

时间:2015-04-14 23:33:41

标签: php html mysql mysqli

我编写了一个显示MySQL表的基本PHP页面。 我真的希望桌子位于页面的顶部,但是我似乎无法使这个工作。它总是排在最后。

以下是我的代码,任何帮助将不胜感激 三江源

<html>
<body>
<center>
<h2>Delete Product Details</h2>
</center>

<?php
include('db_conn.php'); //db connection
include('session.php');

$query = "SELECT * FROM KIT202_Week5";

$result = $mysqli->query($query);

$fields_num = mysqli_num_fields($result);

echo "<table border='0'><tr>";

for($i=0; $i<$fields_num; $i++) {
    $field = mysqli_fetch_field($result);
    echo "<td>{$field->name}</td>";
}
echo "</tr>\n";

while($row = mysqli_fetch_row($result))
{
    echo "<tr>";

    foreach($row as $cell)
        echo "<td>$cell</td>";

    echo "</tr>\n";
}

mysqli_free_result($result);

if (isset($_POST['delete'])) {
    $id = mysqli_real_escape_string($mysqli, $_POST['id']);

    $deleteQuery = "DELETE FROM KIT202_Week5 WHERE ID='$_POST[id]'";

    if ($mysqli->query($deleteQuery) === TRUE) {
        echo "Record deleted successfully";
    } else {
        echo "Error deleting record: " . $mysqli->error;
    }

    header("Location: tute6_delete.php");
}

$mysqli->close();
?>

<h2>Form</h2>
<form method="post" action="tute6_delete.php">
ID: <input type="text" name="id"></br><font color=red>*</font><p>
<input type="submit" value="delete" name="delete">
<input type="reset" value="reset"><p>
<input type="button" value="Go back to Main" onClick="window.location.href='signin_success.php'">
</form>

</body>
</html>

1 个答案:

答案 0 :(得分:4)

该表格显示在页面底部,因为您忘记使用</table>关闭该表格。

浏览器希望在弄清楚如何绘制之前查看所有表格。它将呈现它遇到的其他东西 - 表单等 - 因为那就是全部,但它仍然希望在放出表之前得到</table>。当它到达页面的末尾时,它知道它不会再获得任何表格,所以即使它不完整也会绘制它所拥有的表格。