我正在尝试将 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;
}
谢谢你的帮助!
最佳答案
您缺少一个 </tr>
在您的 While 循环之后,这可能会破坏您的表格:
//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
}
关于php - 试图将 sql 数据库显示到 php 网页中,CSS 没有工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20673047/