首页 > 解决方案 > 一旦表格被转置,提交表格将不起作用

问题描述

我需要转置/旋转表格,以便更好地查看它,但是一旦我转置表格,提交按钮现在将不再起作用我有一个表格设置如下

<table id="tableID" width="200" border="1">
  <tbody>
    <tr>
      <td>Date</td>
      <td>Boxed;</td>
      <td>Location</td>
      <td>Quantity</td>
      <td>Change;</td>
    </tr>
       <?php do { ?>
    <tr><form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">
      <td><?php echo $row_get['Date']; ?></td>
      <td><?php echo $row_get['Boxed']; ?></td>
      <td><input name="Location" type="text" id="Location" value="<?php echo $row_get['Location']; ?>" size="7" /></td>
      <td><input name="Quantity" type="text" id="Quantity" value="<?php echo $row_get['Quantity']; ?>" size="7" /></td>
      <td><input name="Update" type="submit" value="submit" id="Update" />
        <input name="id" type="hidden" id="id" value="<?php echo $row_get['id']; ?>" />
        </p>
        <input type="hidden" name="MM_update" value="form1" />
</form></td>
    </tr> <?php } while ($row_get ->fetch()); ?>
  </tbody>
</table>

转置表脚本中:

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script>
 $( document ).ready(function() {
$("#tableID").each(function() {
        var $this = $(this);
        var newTransposedRow = [];
        $this.find("tr").each(function(){
            var i = 0;
            $(this).find("td").each(function(){
                i++;
                if(newTransposedRow[i] === undefined) { newTransposedRow[i] = $("<tr></tr>"); }
                newTransposedRow[i].append($(this));
            });
        });
        $this.find("tr").remove();
        $.each(newTransposedRow, function(){
            $this.append(this);
        });
    });
});
</script>

更新数据库:

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = "UPDATE Stock SET Location=?, Quantity=? WHERE id=?";

  $Result1= $conn->prepare($updateSQL) or die(errorInfo());
  $done = $Result1->execute([$_POST['Location'], $_POST['Quantity'], $_POST['Trade_price'],  $_POST['id']]);
if ($done){
header('Location: mypage.php
    exit();
    }
}

在我使用/插入转置脚本之前,这一切都很好,知道是什么停止了更新吗?欢迎任何帮助

标签: javascriptphpjquery

解决方案


推荐阅读