我可能没有正确措辞,但基本上这就是我想要做的:
- 在 HTML 表格中显示排行榜
- 排行榜中的每个标题都是一个链接(例如分数、时间、击杀数)
- 单击每个链接时,它会根据单击的链接对表格进行排序(例如,如果单击击杀,则会对在顶部显示移动击杀的数据进行排序)
这是我当前排行榜的链接,它工作正常。
这是我必须到目前为止的代码:
<div id="board">
<table border="1" cellspacing="0" cellpadding="2" width="620"><tbody>
<thead>
<tr>
<td>Name</td>
<td>Score</td> <---- WHEN CLICK = SORT IT BY SCORE
<td>Wave Reached</td> <---- WHEN CLICK = SORT IT BY WAVE
<td>Seconds Survived</td> <---- WHEN CLICK = SORT IT BY SECONDS
<td>Kills</td> <---- WHEN CLICK = SORT IT BY KILLS
<td>Deaths</td> <---- WHEN CLICK = SORT IT BY DEATHS
</tr>
</thead>
<tbody>
<?php
$connect = mysql_connect("localhost","localhost", "password");
if (!$connect) {
die(mysql_error());
}
mysql_select_db("staroids");
$results = mysql_query("SELECT name, score, wave, seconds, kills, deaths FROM scores ORDER BY score DESC LIMIT 10");
while($row = mysql_fetch_array($results)) {
$name = $row['name'];
$score = $row['score'];
$wave = $row['wave'];
$seconds = $row['seconds'];
$kills = $row['kills'];
$deaths = $row['deaths'];
?>
<tr>
<td><?php echo $name;?></td>
<td><?php echo $score;?></td>
<td><?php echo $wave;?></td>
<td><?php echo $seconds;?></td>
<td><?php echo $kills;?></td>
<td><?php echo $deaths;?></td>
</tr>
<?php
}
mysql_close($connect);
?>
</tbody>
</table>
</div>
我希望这能解释我打算做什么。
上面的代码按降序显示分数。当在 HTML 中按下链接时,是否可以运行 PHP 脚本(如使用 JavaScript)以便运行特定查询?