0

我需要它做的是访问我的数据库并获取我在那里的数据。虽然它不起作用。我得到了一个没有数据的表格!随着更多数据的添加,它仍然会生成新表,只是不添加数据。这是我的php:

 <?php 

 mysql_connect("localhost", "", "")

 or die(mysql_error()); 

 mysql_select_db("tcordero_playtime") or die(mysql_error()); 

 $query = mysql_query("SELECT * FROM players") 

 or die(mysql_error()); 
if (mysql_num_rows($query) == 0) {
    echo "No player information has been entered yet!";
}
else {
 Print "<table border cellpadding=1>"; 

 while($row = mysql_fetch_array( $query )) 

 { 

 Print "<tr>"; 

 Print "<th>Playername:</th> <td>".$query['playerName'] . "</td> "; 

 Print "<th>Total playtime:</th> <td>".$query['playtime' / 1000 / 60] . "</td> ";

 } 

 Print "</table>"; 
}
 ?>

此外,时间在数据库中以毫秒为单位。我如何让它们在几分钟甚至几小时内显示出来?这是该页面的示例以及出了什么问题:http ://tomascordero.com/example/playertime.php

4

4 回答 4

1

它应该是$row['playerName'],等等,而不是$query['playerName']。打开错误日志,应该会更明显。

于 2013-03-09T03:47:45.043 回答
1

在此行中将 $query 更改为 $row:

Print "<th>Playername:</th> <td>".$query['playerName'] . "</td> "; 

Print "<th>Total playtime:</th> <td>".$query['playtime' / 1000 / 60] . "</td> ";

Print "<th>Playername:</th> <td>".$row['playerName'] . "</td> "; 

Print "<th>Total playtime:</th> <td>".$row['playtime' / 1000 / 60] . "</td> ";
于 2013-03-09T03:50:52.090 回答
0

您可以像这样更改编码

玩家名称:".$row['playerName'] ." ";

打印 "总游戏时间:".$row['playtime' / 1000 / 60] 。"

于 2013-03-09T04:15:35.590 回答
0

你必须使用$row['playerName']not $query['playerName']

您正在检索 $row 的值,因此应该使用 $row 来获取值。

<tr>应该关闭。在您的代码<tr>中没有关闭。

于 2013-03-09T03:51:44.163 回答