2012-04-04 43 views
-1

我想在php頁面中顯示一個包含我數據庫數據的表。使用PHP顯示Mysql數據給了我一個空白頁

完全沒問題。

當我嘗試使用css使表更好看瀏覽器給我一個空白頁。 這裏是我的代碼... 如果我打開表標記後,刪除id = csstest部分一切正常,只要我添加id = csstest我得到一個空白頁... 我做錯了什麼?

<?php 

include 'config.php'; 

if (!mysql_connect($db_host, $db_user, $db_pwd)) 
    die("Can't connect to db"); 

if (!mysql_select_db($database)) 
    die("Can't select db"); 

// sending query 
$result = mysql_query("SELECT data, cur_timestamp FROM {$table}"); 
if (!$result) { 
    die("Check your SQL query"); 
} 

$fields_num = mysql_num_fields($result); 

echo "<h1>Tabella: {$table}</h1>"; 
echo "<table id="csstest"><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); 
mysql_close($result); 
?> 
</table> 
+0

的嘗試'回聲「<表ID = \」 csstest \「>」;' – 2012-04-04 09:32:06

+0

非常感謝! 如果你把它寫成答案,我會選擇它作爲正確的:) – Pitto 2012-04-04 09:39:36

+2

那麼,只要選擇'跳躍的青蛙' – 2012-04-04 09:41:03

回答

4

更改以下語句:

echo "<table id="csstest"><tr>"; 

這樣:

echo "<table id=\"csstest\"><tr>"; 
4

你需要在雙引號前加斜槓:

echo "<table id=\"csstest\"><tr>"; 
1
echo "<table id="csstest"><tr>"; 

上面的代碼生成語法錯誤,並且你的錯誤報告是關閉,因此它只是顯示空白頁 試穿以下方法

echo "<table id='csstest'><tr>"; 
echo '<table id="csstest"><tr>'; 
echo "<table id=\"csstest\"><tr>";