如果mySQL行的innerHTML X然后将其移动到表的顶部

时间:2018-05-25 07:46:17

标签: php mysql

这个PHP代码打印出来自mySQL的表格 如果id为" thisone"我有innerHTML 2我希望将整行移到表格的顶部,包括用户名杀戮和死亡,因为它们在同一行中对齐。

我认为这个mySQL打印出来应该会更好但是我真的不知道如何打印这个有效的替代品。

以下是表格未被触及的方式。如你所见它有1& 2到底。我希望团队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);
?>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

也许使用jQuery:

&#13;
&#13;
// read the value
var thisone = $('#thisone');
// check, if value is '2'
if (thisone === parseInt(2)) {
	var player = $(thisone).parent();
  $(player).prepend('#myTable');
}
&#13;
&#13;
&#13;

编辑:您可以粘贴生成的HTML吗?