【发布时间】:2013-09-17 16:26:52
【问题描述】:
我正在尝试从我的 MySQL 数据库中显示我的表。它似乎不起作用,我想这很可能是简单的事情。如果可能的话,我想让这张桌子看起来像一张没有装饰的普通桌子;只是一个边框,并且能够适应正常大小的页面。这是我目前所拥有的:
<html>
<head>
<title>Profile Database </title>
</head>
<body>
<?
$connection = "connect.php";
require $connection;
mysql_select_db("bank");
$sql = "SELECT * FROM profiles";
$result = mysql_query($sql);
?>
<table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" >
<thead>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>E-Mail</th>
<th>DOB</th>
<th>Age</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>Offence</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<?php
while( $row = mysql_fetch_assoc( $result ))
{
echo <tr>
<td>{$row\['id'\]}</td>
<td>{$row\['fname'\]}</td>
<td>{$row\['lname'\]}</td>
<td>{$row\['email'\]}</td>
<td>{$row\['dob'\]}</td>
<td>{$row\['age'\]}</td>
<td>{$row\['city'\]}</td>
<td>{$row\['state'\]}</td>
<td>{$row\['zip'\]}</td>
<td>{$row\['offence'\]}</td>
<td>{$row\['notes'\]}</td>
</tr>\n;
}
?>
</tbody>
</table>
<?php
mysql_close($connection);
?>
</body>
</html>
【问题讨论】:
-
您没有打开/关闭表格行 -
<tr>...</tr> -
您是否遇到任何错误?它似乎不起作用,意味着您遇到错误或 o/p 不是您想要的..
-
你缺少
<tr>标签,mysql_函数也被弃用了,你不应该再使用它们,了解prepared statements,改用PDO或MySQLi-@987654324 @ 将帮助您决定哪个。 -
非常感谢,我不知道。哈哈,我在过去的半小时里一直在阅读它,这似乎是我需要了解更多的东西。