【发布时间】:2013-08-08 14:39:10
【问题描述】:
我不明白为什么这不起作用,我已经坚持了很长时间并尝试了许多不同的替代方案,但它只是不打印数据库中的数据。
目前我只是想打印 id,但最终我想打印数据库中的大部分数据(不包括哈希)。
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<title>Staroids Leaderboard</title>
</head>
<body>
<table border=1px>
<thead>
<tr>
<td>name</td>
<td>score</td>
</tr>
</thead>
<tbody>
<?php
$connect = mysql_connect("localhost","root", "password");
if (!$connect) {
die(mysql_error());
}
mysql_select_db("staroids");
$results = mysql_query("SELECT id FROM scores");
while($row = mysql_fetch_array($results)) {
$name = $row['id']
?>
<tr>
<td><?php echo '$name'?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</body>
</html>
下图显示了它在 html 中的样子:
此图显示本地主机中的数据库,您可以看到有很多数据,但似乎没有打印名称?!
【问题讨论】:
标签: php mysql sql html-table