2012-03-14 9 views
2

私のページには、テーブル(MySQLのコンテンツ)とフッタ(require_once()を使用)があります。PHP/MySQL:テーブルの前にフッタが表示される

問題は、「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"); 
?> 

ありがとう!

答えて

5

テーブルを作成するループの後でテーブルタグを閉じることはありません。

echo "</table>"; 

whileループの後に配置します。

+0

を入れ

はあなたにみんなありがとう!私はそのテーブルのタグを見逃しているに違いない。 – user1261817

1

は、私はあなたが、テーブルタグを閉じるために必要があると思う:

mysql_free_result($result); 
echo "</table>" 
require_once("footer.php"); 
?> 
1

あなたは</table>タグを閉じていることを確認します。

また、これはCSSの問題かもしれません。

1

テーブルの終了タグはど​​こですか?この

echo "</table>"; 
関連する問題