-1

我正在尝试在 php 页面中显示包含来自我的数据库的数据的表。

完全没有问题。

当我尝试使用 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>
4

3 回答 3

4

更改以下语句:

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

对此:

echo "<table id=\"csstest\"><tr>";
于 2012-04-04T09:32:16.540 回答
4

您需要在双引号之前添加斜杠:

echo "<table id=\"csstest\"><tr>";
于 2012-04-04T09:32:23.067 回答
1
echo "<table id="csstest"><tr>";

上面的代码生成解析错误并且您的错误报告已关闭,因此它只显示空白页面尝试以下方法

echo "<table id='csstest'><tr>";
echo '<table id="csstest"><tr>';
echo "<table id=\"csstest\"><tr>";
于 2012-04-04T10:32:59.580 回答