【发布时间】:2019-02-27 11:58:50
【问题描述】:
我是 php 和 jquery 的新手,我正在尝试创建一个网页,根据来自 Mysql 服务器的数据显示玩家及其状态。
基本代码有效,尽管代码是从多个 youtube 教程中拼凑而成的 :)
我想在玩家行的状态为或变为 0(死亡)时更改其不透明度。
这是我到目前为止的代码:
pagetest.php:
<!DOCTYPE html>
<html>
<head>
<title>pagetest</title>
</head>
<body>
<table id="show">
<tr>
<td>player</td>
<td>status</td>
</tr>
</table>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
setInterval(function() {
$('#show').load('test.php')
}, 3000);
});
</script>
</body>
</html>
test.php:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<?php
$conn = mysqli_connect("myserver", "myuser", "mypass", "mydb");
if ($conn-> connect_error) {
die("Connection failed:". $conn->connect_error);
}
$sql = "SELECT player, status FROM mytable";
$result = $conn->query($sql);
if ($result-> num_rows > 0) {
while ($row = $result->fetch_assoc()){
echo "<tr><td>" . $row["player"] . "</td><td>" . $row["status"] . "</td></tr>";
}
echo "</table>";
}
else {
echo "No game data available";
}
?>
</body>
</html>
非常感谢您的帮助:)
【问题讨论】:
标签: javascript php jquery html mysql