我是web dev,PHP,CSS和html的新手。我想在我的表中放置一个CSS,在我的数据库中显示数据,但它不起作用。
这是我的代码:
我的CSS文件名为“table.css”...
<html>
<head>
<title>WEW</title>
<head>
<link href="table.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
$con = mysql_connect("localhost","abc123","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database_ME", $con);
$result = mysql_query("SELECT * FROM id");
$data->set_css_class("table");
echo "<table class="table">
<tr>
<th>id</th>
<th>password</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['password'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "</div>";
mysql_close($con);
?>
</body>
</html>
答案 0 :(得分:3)
我假设CSS文件写得很好,而且它使用了.table
选择器。
那里有几个语法错误,都是因为你需要像这样转义内部"
:
echo "A 'string with several \"nesting\" levels' needs escaping.";
答案 1 :(得分:0)
echo "<table class="table">
更改为
echo "<table class='table'>
和
echo "<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">";
更改为
echo "<tr onmouseover=\"this.style.backgroundColor='#ffff66';\" onmouseout=\"this.style.backgroundColor='#d4e3e5';\">";