【问题标题】:trying to display sql database into php webpage, the CSS didnt work试图将 sql 数据库显示到 php 网页中,CSS 不起作用
【发布时间】:2013-12-19 12:02:08
【问题描述】:

我正在尝试将 sql 数据库显示到 php 网页中的表中。一开始一切都很顺利。但是当我插入 CSS 时,表格没有工作,我不知道为什么。我试图重新定位代码,它也没有工作:(

<?php

session_start();
if(!empty($_SESSION['pswd']))
{
        header("location:form.html");
}

?>

<html>
<head>
<link href="table.css" type="text/css"/>
</head>

<body>
<div class="tablee" style="width:1100px;height:100px;">

<?php

    $connection = mysql_connect("localhost", "root", "" );

if (!$connection)
{
    die('Could not connect:' .mysql_error());
}

mysql_select_db("permohonan_data", $connection);

    $result = mysql_query("SELECT * FROM pemohon");

//this is table
echo"<table>
<tr>
<th>NAME</th>
<th>POSITION</th>
<th>UNIT</th>
<th>DEPARTMENT</th>
<th>TELEFON</th>
<th>FAKS</th>
<th>E-mail</th>
<th>DATA</th>
<th>REASON</th>
</tr>";

//table with data
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['position'] . "</td>";
echo "<td>" . $row['unit'] . "</td>";
echo "<td>" . $row['department'] . "</td>";
echo "<td>" . $row['telefon'] . "</td>";
echo "<td>" . $row['faks'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['data'] . "</td>";
echo "<td>" . $row['reason'] . "</td>";
}
echo "</table>";

print "<p>Please feel free to drop by again!<br>";

mysql_close($connection);
?>

</div>
</body>
</html>

这是 CSS

.tablee {
    margin:0px;padding:0px;
    width:100%;
    box-shadow: 10px 10px 5px #888888;
    border:1px solid #000000;
    -moz-border-radius-bottomleft:9px;
    -webkit-border-bottom-left-radius:9px;
    border-bottom-left-radius:9px;
    -moz-border-radius-bottomright:9px;
    -webkit-border-bottom-right-radius:9px;
    border-bottom-right-radius:9px;
    -moz-border-radius-topright:9px;
    -webkit-border-top-right-radius:9px;
    border-top-right-radius:9px;
    -moz-border-radius-topleft:9px;
    -webkit-border-top-left-radius:9px;
    border-top-left-radius:9px;
}

.tablee table {
    width:100%;
    height:100%;
    margin:0px;padding:0px;
}

.tablee tr:last-child td:last-child {
    -moz-border-radius-bottomright:9px;
    -webkit-border-bottom-right-radius:9px;
    border-bottom-right-radius:9px;
}

.tablee table tr:first-child td:first-child {
    -moz-border-radius-topleft:9px;
    -webkit-border-top-left-radius:9px;
    border-top-left-radius:9px;
}

.tablee table tr:first-child td:last-child {
    -moz-border-radius-topright:9px;
    -webkit-border-top-right-radius:9px;
    border-top-right-radius:9px;
}

.tablee tr:last-child td:first-child {
    -moz-border-radius-bottomleft:9px;
    -webkit-border-bottom-left-radius:9px;
    border-bottom-left-radius:9px;
}

.tablee tr:hover td {
    background-color:#82c0ff;
    background:-o-linear-gradient(bottom, #82c0ff 5%, #56aaff 100%);    background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #82c0ff), color-stop(1, #56aaff) );
    background:-moz-linear-gradient( center top, #82c0ff 5%, #56aaff 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#82c0ff", endColorstr="#56aaff");  background: -o-linear-gradient(top,#82c0ff,56aaff);
}

.tablee tr:first-child td {
    background:-o-linear-gradient(bottom, #0069d3 5%, #007fff 100%);    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #0069d3), color-stop(1, #007fff) );
    background:-moz-linear-gradient( center top, #0069d3 5%, #007fff 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#0069d3", endColorstr="#007fff");  background: -o-linear-gradient(top,#0069d3,007fff);
    background-color:#0069d3;
    border:0px solid #000000;
    text-align:center;
    border-width:0px 0px 1px 1px;
    font-size:18px;
    font-family:Comic Sans MS;
    font-weight:bold;
    color:#ffffff;
}

.tablee tr:first-child:hover td {
    background:-o-linear-gradient(bottom, #0069d3 5%, #007fff 100%);    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #0069d3), color-stop(1, #007fff) );
    background:-moz-linear-gradient( center top, #0069d3 5%, #007fff 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#0069d3", endColorstr="#007fff");  background: -o-linear-gradient(top,#0069d3,007fff);
    background-color:#0069d3;
}

.tablee tr:first-child td:first-child {
    border-width:0px 0px 1px 0px;
}

.tablee tr:first-child td:last-child {
    border-width:0px 0px 1px 1px;
}

.tablee td {
    background:-o-linear-gradient(bottom, #56aaff 5%, #82c0ff 100%);    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #56aaff), color-stop(1, #82c0ff) ); 
    background:-moz-linear-gradient( center top, #56aaff 5%, #82c0ff 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#56aaff", endColorstr="#82c0ff");  background: -o-linear-gradient(top,#56aaff,82c0ff);
    background-color:#56aaff;
    border:1px solid #000000;
    border-width:0px 1px 1px 0px;
    text-align:left;
    padding:7px;
    font-size:12px;
    font-family:Comic Sans MS;
    font-weight:bold;
    color:#000000;
}

.tablee tr:last-child td {
    border-width:0px 1px 0px 0px;
}

.tablee tr td:last-child {
    border-width:0px 0px 1px 0px;
}

.tablee tr:last-child td:last-child {
    border-width:0px 0px 0px 0px;
}

感谢您的帮助!

【问题讨论】:

  • css 的哪一部分不起作用?您有内联样式 '
    ' 会覆盖 CSS 文件中的任何内容,即 .tablee width=100%
  • @user934902 即使我没有内联样式,css 部分也不起作用..

标签: php css sql html wamp


【解决方案1】:

您在 While 循环之后缺少 &lt;/tr&gt;,这可能会破坏您的表格:

//table with data
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['position'] . "</td>";
echo "<td>" . $row['unit'] . "</td>";
echo "<td>" . $row['department'] . "</td>";
echo "<td>" . $row['telefon'] . "</td>";
echo "<td>" . $row['faks'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['data'] . "</td>";
echo "<td>" . $row['reason'] . "</td>";
echo "</tr>";  // Add this in
}

【讨论】:

  • 向我们展示 CSS。上面显示的只是文件的include。
  • 对不起,我添加了 CSS
猜你喜欢
相关资源
最近更新 更多
热门标签