我正在尝试在 php 页面中显示包含来 self 的数据库的数据的表格。
完全没有问题。
当我尝试使用 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>
最佳答案
更改以下语句:
echo "<table id="csstest"><tr>";
为此:
echo "<table id=\"csstest\"><tr>";
关于php - 使用 PHP 显示 Mysql 数据给我一个空白页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10008437/