这个问题在这里已经有答案了:
mysql:将特定记录移到order by(4个答案)旁边的结果数组顶部
两年前关门了。
这段php代码从mysql打印出一个表。
如果id为“thisone”的行中有innerHTML2,我想将整行移到表的顶部,包括username kills和death,因为它们在同一行中对齐。
我认为这个mysql打印输出应该更好,但我真的不知道如何打印的东西属性这一个工作,尽管如此。
这张table看起来没碰过。如你所见,它的结尾有1和2。我要让第二组的所有行都移到最上面。
https://i.imgur.com/zkqrzcb.png
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "username", "pw", "databasename");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Attempt select query execution
$sql = "SELECT * FROM online_players";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table id='myTable'>";
echo "<tr>";
echo "<th>username</th>";
echo "<th>kills</th>";
echo "<th>deaths</th>";
echo "<th>team</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['kills'] . "</td>";
echo "<td>" . $row['deaths'] . "</td>";
echo "<td id="thisone">" . $row['team'] . "</td>";
echo "</tr>";
}
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
1条答案
按热度按时间shyt4zoc1#
可能使用jquery:
编辑:你能粘贴你生成的html吗?