【问题标题】:Table html/CSS output error: unexpected T_STRING表 html/CSS 输出错误:意外的 T_STRING
【发布时间】:2011-08-28 17:04:24
【问题描述】:

我是 web 开发、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>

【问题讨论】:

标签: php css mysql html-table


【解决方案1】:

我假设 CSS 文件写得很好,并且它使用了 .table 选择器。

里面有几个语法错误,都是因为你需要像这样转义内部的"

echo "A 'string with several \"nesting\" levels' needs escaping."; 

【讨论】:

    【解决方案2】:
    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';\">";
    

    【讨论】:

    • 效果很好,求帮助!我希望当我单击它时该行也发生变化,然后当我转到其他列时它保持该颜色。这可能吗?这是我的css文件:table.hovertable{font-family: verdana,arial,sans-serif;font-size:11px;color:#333333;border-width: 1px;border-color: #999999;边框折叠:折叠; } table.hovertable th {background-color:#F0E68C;border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9; } table.hovertable tr {背景颜色:#d4e3e5; } table.hovertable td {border-width: 1px;padding: 8px;border-style:solid;border-color: #a9c6c9; }
    • @jack,你不能在评论中提出这个问题,因为如果有人搜索相同的案例,它不会显示。您可以在此处接受或点赞某个答案,然后通过单击此页面右上角的“”按钮提出新问题,这样您就可以从其他人那里得到很多答案,其他人也可以从您的问题中学习。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多