PHP/MySQL:在表格之前显示的页脚(由数据库提供支持)

use*_*817 2 php sql

在我的页面上,我有一个表(来自MySQL的内容)和一个页脚(使用require_once()).

问题是,即使是"require_once("footer.php");" 代码行是在我的表格显示代码之后,页脚显示在我的表格上方.

这是我的代码:

$table='mytable';
$result = mysql_query("SELECT * FROM {$table}");
if (!$result) {
    die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);

//echo "<h1>Table: {$table}</h1>";
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
    echo "<tr>";

    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    foreach($row as $cell)
        echo "<td>$cell</td>";

    echo "</tr>\n";
}
mysql_free_result($result);
?>

<?
    require_once("footer.php"); 
?>
Run Code Online (Sandbox Code Playgroud)

谢谢!

Vin*_*nie 5

在构造表的循环之后,您没有关闭表标记.

  echo "</table>";
Run Code Online (Sandbox Code Playgroud)

放在while循环之后.