记分牌未出现在右侧的高分数中。它没有显示任何东西。我为我的javascript蛇游戏制作了一个高分板。那么我的MYSQL代码有什么问题吗?
<html>
<link href='style.css' type='text/css' rel='stylesheet'>
<!-- Lets make a simple snake game -->
<canvas id="canvas" width="450" height="450" style="border:1px solid #000000;"></canvas>
<!-- Jquery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript">
</script>
<script src="snake.js" type="text/javascript"></script>
<?php $score = "<script>document.write(score)</script>"?>
<p id = 'demo'>Your Final Score: <script>score</script></p>
<div id = 'right'>
<div id = 'rightForm'>
<form action="highscoreregistry.php" method="post">
<input type="hidden" name="score" id="score">
</form>
</div>
<div id = 'rightHighScore' style = 'size:9px;'>
<?php
$servername = "-";
$username = "-";
$password = "-";
$dbname = "-";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT Name, Score, Date FROM snakehiscore";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><th>ID</th><th>Name</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["Name"]."</td><td>".$row["Score"]." ".$row["Date"]."</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
</div>
</div>
</html>
答案 0 :(得分:-4)
在查询中添加分号!所以:
$ sql =“SELECT名称,分数,日期来自snakehiscore;”;
2.而不是使用它:
$result = $conn->query($sql);
如果您安装了mysqli,请尝试此操作:
$result = mysqli_query($conn, $sql);
mysqli_num_rows($result) > 0