我可以从数据库中获取一个分数,但由于某种原因,我不断得到一个错误: 注意:未定义的索引:在第26行的/var/www/html/game.php中得分
游戏所在的PHP文件:
<html>
<title>Breakout!</title>
<style>
@import url('https://fonts.googleapis.com/css?family=Press+Start+2P');
</style>
<?php include "db.php"; ?>
<link rel="icon" href="http://i.imgur.com/UJ9CaVW.png">
<head>
<style>{ padding: 0; margin: 0; } canvas { background: #eee; display: block; margin: 0 auto; }</style>
</head>
<?php include 'stylesheet.php'; ?>
<?php include 'navbar.php'; ?>
<?php include 'opennavdiv.php' ?>
<body>
<div id="countdown"></div>
<!-- <audio src="Nintendo - Switch.mp3" autoplay="" loop=""></audio> -->
<div class="gamecon">
<canvas id="myCanvas" width="960" height="640"></canvas>
<script src='game.js' type="text/javascript"></script>
<?php include 'closenavdiv.php' ?>
</div>
<table>
<tr>
<td>Rank</td>
<tr>
<?php $score = DB::leaderboard($_GET["score"]); ?>
<?php echo $score['score']; ?>
</tr>
<td>Name</td>
<td>Score</td>
</tr>
</table>
</body>
</html>
我的db.php文件上的排行榜功能:
public static function leaderboard() {
$connection = DB::CreateConnection();
$rawResults = $connection->query("SELECT name, score FROM scores ORDER BY score DESC");
$name = $rawResults->fetch_assoc();
$score = $rawResults->fetch_assoc();
return $name;
return $score;
$rank = 1;
if (mysql_num_rows($result)) {
while ($row = mysql_fetch_assoc($result)) {
echo "<td>{$rank}</td>
<td>{$row['name']}</td>
<td>{$row['score']}</td>";
$rank++;
}
}
}