Javascript PHP将行从一个表移动到另一个表

Javascript PHP将行从一个表移动到另一个表,javascript,php,jquery,row,html-table,Javascript,Php,Jquery,Row,Html Table,我一页有两张桌子。顶部的表只有一行,因为DB中的特定表只有一个条目,即当月的储罐。底部的表显示了数据库中另一个表“uploads”的内容。当从底部表中删除项目时,它会按预期从数据库和物理/上传/文件夹中删除该项目。当一个项目从底部表格中被选为当月储罐时,它应该从底部表格中消失,这是正确的,然后顶部表格应该被清除,并且所选的项目应该自动淡入顶部表格。到目前为止,我已经尝试了很多很多方法,但都没有成功。我要刷新顶部表的唯一方法是实际刷新页面。这是我想要的,但我不想刷新页面 totm.php(不是整个

我一页有两张桌子。顶部的表只有一行,因为DB中的特定表只有一个条目,即当月的储罐。底部的表显示了数据库中另一个表“uploads”的内容。当从底部表中删除项目时,它会按预期从数据库和物理/上传/文件夹中删除该项目。当一个项目从底部表格中被选为当月储罐时,它应该从底部表格中消失,这是正确的,然后顶部表格应该被清除,并且所选的项目应该自动淡入顶部表格。到目前为止,我已经尝试了很多很多方法,但都没有成功。我要刷新顶部表的唯一方法是实际刷新页面。这是我想要的,但我不想刷新页面

totm.php(不是整个文件,因为大部分文件都有效):

}))

}))

您可以使用该函数将项附加到适当的表中。 看看怎么做

要获取“当前”表,请签出


我自己正在学习javascript和jquery,所以可能有更好的方法。

您尝试过用什么jquery将表行从下表移动到上表?好吧,我想我可以这样做:current.fadeOut('slow')、function(){$(this.closest('tr').empty()});清除顶部表,然后清除current.fadeIn('slow',function(){$('#'+id).insert()});。问题是如何定义“current”表,它是最上面的一个表。我不能使用var-nestest=$(this.nestest('tr');,我不知道有多少。我必须使用家长,获取“当前”变量非常混乱。可能会让您了解如何处理将tr从一个表移动到另一个表。
<!--put body stuff here-->
    <div class="content">
        <div class="container-fluid">
            <div class="row">                   
                <div class="col-md-12">
                    <div class="card card-plain">
                        <div class="header">
                            <h4 class="title">Current Tank of the Month</h4>
                            <p class="category">This is your current tank of the month. </p>
                        </div>
                        <div class="content table-responsive table-full-width">
                            <?php
                                // Check connection
                                if ($mysqli->connect_error) {
                                    die("Connection failed: " . $mysqli->connect_error);
                                } 
                                else
                                {
                                    if (!$stmt = $mysqli->query("SELECT * FROM totm")) {
                                        echo "Query Failed!: (" . $mysqli->errno . ") ". $mysqli->error;
                                    }

                                    echo "<table class='table table-hover'>";
                                    echo "<thead>
                                            <th>Image</th>
                                            <th>Filename</th>
                                            <th>Description</th>
                                            </thead>
                                            <tbody>";
                                    while ($row = mysqli_fetch_array($stmt)) {
                                        $i = $row["id"];
                                        $f = $row["file"];
                                        $d = $row["description"];
                                        echo "<tr id='$i' file='$f' desc='$d'>";
                                        echo "<td> <a href='../assets/img/totm/" . $row["file"] . "'><img class='thumbnail' src='../assets/img/totm/" . $row["file"] . "' alt='" . $row["file"] . "' /> </td>";
                                        echo "<td>" . $row["file"] . "</td>";
                                        echo "<td>" . $row["description"] . "</td>";
                                        echo "</tr>";
                                    }
                                    echo "</tbody>";
                                    echo "</table>";

                                    if (mysqli_num_rows($stmt) == 0) {
                                        echo "No records found.";
                                    }
                                } 
                            $stmt->free();
                            //$mysqli->close();    
                            ?>       
                        </div>
                    </div>
                </div>                
            </div>                    
        </div>
        <div class="container-fluid">
            <div class="row">                   
                <div class="col-md-12">
                    <div class="card card-plain">
                        <div class="header">
                            <h4 class="title">Current Entries</h4>
                            <p class="category">Here you will find the current entries for the Tank of the Month contest. Select one as the new Tank of The Month and delete the rest. Keep it clean around here! </p>
                        </div>
                        <div class="content table-responsive table-full-width">
                            <?php
                                // Check connection
                                if ($mysqli->connect_error) {
                                    die("Connection failed: " . $mysqli->connect_error);
                                } 
                                else
                                {
                                    if (!$stmt = $mysqli->query("SELECT * FROM uploads")) {
                                        echo "Query Failed!: (" . $mysqli->errno . ") ". $mysqli->error;
                                    }

                                    echo "<table class='table table-hover'>";
                                    echo "<thead>
                                            <th>Image</th>
                                            <th>Name</th>
                                            <th>Email</th>
                                            <th>IP</th>
                                            <th>Date</th>
                                            <th>Description</th>
                                            <th>Action</th>
                                            </thead>
                                            <tbody>";
                                    while ($row = mysqli_fetch_array($stmt)) {
                                        $i = $row["id"];
                                        $f = $row["file"];
                                        $d = $row["description"];
                                        echo "<tr id='$i' file='$f' desc='$d'>";
                                        echo "<td> <a href='../uploads/" . $row["file"] . "'><img class='thumbnail' src='../uploads/" . $row["file"] . "' alt='" . $row["file"] . "' /> </td>";
                                        echo "<td>" . $row["name"] . "</td>";
                                        echo "<td>" . $row["email"] . "</td>";
                                        echo "<td>" . $row["ip"] . "</td>";
                                        echo "<td>" . $row["date"] . "</td>";
                                        echo "<td>" . $row["description"] . "</td>";
                                        echo "<td>
                                                  <button class='btn btn-round btn-danger deleteitem'>Delete</button>
                                                  <div class='space-20'></div>
                                                  <button class='btn btn-round btn-success chooseitem'>Select</button>
                                              </td>";
                                        echo "</tr>";
                                    }
                                    echo "</tbody>";
                                    echo "</table>";

                                    if (mysqli_num_rows($stmt) == 0) {
                                        echo "No records found.";
                                    }
                                } 
                            $stmt->free();
                            $mysqli->close();    
                            ?>       
                        </div>
                    </div>
                </div>                
            </div>                    
        </div>
    </div>
$(".deleteitem").click(function () {
var parent = $(this).closest('TR');
var id = parent.attr('id');
var file = parent.attr('file');

if (confirm("Are you sure you want to delete this?")) {
    $.ajax({
        type: "POST",
        data: { delete_id: id, delete_file : file },
        URL: "totm.php",

        success: function (msg) {
            parent.fadeOut('slow', function () { $('#' + id).remove() });
        }
    });
}
return false;
$(".chooseitem").click(function () {
var parent = $(this).closest('tr');
var id = parent.attr('id');
var file = parent.attr('file');
var desc = parent.attr('desc');

if (confirm("Are you sure you want to promote this to Tank of the Month?")) {
    $.ajax({
        type: "POST",
        data: { promote_id: id, promote_file: file, promote_desc: desc },
        URL: "totm.php",

        success: function (msg) {
            parent.fadeOut('slow', function () { $('#' + id).remove() });
        }
    });
}
return false;