捕获动态表中 HTML 元素的值

2024-05-13

我有从数据库生成的以下动态表。

<form method="post">
    <?php
    while($result = mysqli_fetch_array($tableQueryExecute)){

        $shift1Oa = $result['operator1'];
        $shift2Oa = $result['operator2'];
        $shift3Oa = $result['operator3'];
        $shift4Oa = $result['operator4'];
        $id = $result['srNumber'];

        echo '<td scope="row">'.$id.'</td>
              <td>                         
                    <input type="number" class="form-control" id="shift1PinCount" name="shift1PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 1" min=0>
              </td>

              <td>
                    <input type="text" class="form-control" id="shift1Oa" name="shift1Oa" value="'.$shift1Oa.'" disabled>
              </td>

              <td>
                    <input type="number" class="form-control" id="shift2PinCount" name="shift2PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 2" min=0>
              </td>

              <td>
                    <input type="text" class="form-control" id="shift2Oa" name="shift2Oa" value="'.$shift2Oa.'" disabled>
              </td>

              <td>
                    <input type="number" class="form-control" id="shift3PinCount" name="shift3PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 3" min=0>
              </td>

              <td>
                    <input type="text" class="form-control" id="shift3Oa" name="shift3Oa" value="'.$shift3Oa.'" disabled>
              </td>

              <td>
                    <input type="number" class="form-control" id="shift4PinCount" name="shift4PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 4" min=0>
              </td>

              <td>
                    <input type="text" class="form-control" id="shift4Oa" name="shift4Oa" value="'.$shift4Oa.'" disabled>
              </td>

              <td><input class="form-control" type="date" id="shiftDate" name="shiftDate" value="'.date("Y-m-d").'"></td>

              <td>
                <a href="supervisorEdit.php?source='.$id.'" type="submit" class="btn btn-primary" name="savePcData" id="savePcData" value="savePcData">Save</a>
              </td>';

    }

</form>

我需要的

假设用户点击了Save该表的特定行的按钮,我希望使用该行的相应值保存在数据库中php $_POST or $_GET方法如下

if(isset($_GET['source'])){
    $sourceId = $_GET['source'];
}

Issue

我的问题是,我不知道如何获得$_POST由于每个项目的名称都是动态生成的,因此表单的值是动态生成的。我尝试通过添加唯一的名称来使每个元素的名称都唯一$id其值如下。

<input type="text" class="form-control" id="shift1Oa" name="shift1Oa'.$id.'" value="'.$shift1Oa.'" disabled>

我无法通过以下方法捕获这个唯一的名称值。有谁知道为什么?

if(isset($_GET['source'])){
    $sourceId = $_GET['source'];
    echo $_GET['shift1Oa'.$sourceId];
}

Edit 1

为了获得更好的图片,以下是带有按钮的一行的屏幕截图


如果我没记错的话,请纠正我..在这里您想从表单中获取所有值,对吧?单击按钮提交? 为什么你要制作这个按钮href? 假设我们有 3 个数据到我的 $result 中,循环如下所示

 <form method="post" action="">
<tr>
       <td scope="row"></td>
       <input type ="text" name="sourece" value=1 />
              <td>                         
                    <input type="number" class="form-control" id="shift1PinCount" name="shift1PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 1" min=0>
              </td>

              <td>
                    <input type="text" class="form-control" id="shift1Oa" name="shift1Oa" value="1" disabled>
              </td>

              <td>
                    <input type="number" class="form-control" id="shift2PinCount" name="shift2PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 2" min=0>
              </td>

              <td>
                    <input type="text" class="form-control" id="shift2Oa" name="shift2Oa" value="2" disabled>
              </td>

              <td>
                    <input type="number" class="form-control" id="shift3PinCount" name="shift3PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 3" min=0>
              </td>

              <td>
                    <input type="text" class="form-control" id="shift3Oa" name="shift3Oa" value="3" disabled>
              </td>

              <td>
                    <input type="number" class="form-control" id="shift4PinCount" name="shift4PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 4" min=0>
              </td>

              <td>
                    <input type="text" class="form-control" id="shift4Oa" name="shift4Oa" value="4" disabled>
              </td>

              <td><input class="form-control" type="date" id="shiftDate" name="shiftDate" value="<?=date("Y-m-d")?>"></td>

              <td>
                <input type="submit" class="btn btn-primary" name="savePcData" id="savePcData" value="savePcData">
              </td> 
</form>
</tr>
<form method="post" action="">
<tr>
       <td scope="row"></td>
       <input type ="text" name="sourece" value=2 />
              <td>                         
                    <input type="number" class="form-control" id="shift1PinCount" name="shift1PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 1" min=0>
              </td>

              <td>
                    <input type="text" class="form-control" id="shift1Oa" name="shift1Oa" value="11" disabled>
              </td>

              <td>
                    <input type="number" class="form-control" id="shift2PinCount" name="shift2PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 2" min=0>
              </td>

              <td>
                    <input type="text" class="form-control" id="shift2Oa" name="shift2Oa" value="22" disabled>
              </td>

              <td>
                    <input type="number" class="form-control" id="shift3PinCount" name="shift3PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 3" min=0>
              </td>

              <td>
                    <input type="text" class="form-control" id="shift3Oa" name="shift3Oa" value="33" disabled>
              </td>

              <td>
                    <input type="number" class="form-control" id="shift4PinCount" name="shift4PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 4" min=0>
              </td>

              <td>
                    <input type="text" class="form-control" id="shift4Oa" name="shift4Oa" value="44" disabled>
              </td>

              <td><input class="form-control" type="date" id="shiftDate" name="shiftDate" value="<?=date("Y-m-d")?>"></td>

              <td>
                <input type="submit" class="btn btn-primary" name="savePcData" id="savePcData" value="savePcData">
              </td> 
</form>
</tr>
<form method="post" action="">
<tr>
       <td scope="row"></td>
       <input type ="text" name="sourece" value=3 />
              <td>                         
                    <input type="number" class="form-control" id="shift1PinCount" name="shift1PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 1" min=0>
              </td>

              <td>
                    <input type="text" class="form-control" id="shift1Oa" name="shift1Oa" value="111" disabled>
              </td>

              <td>
                    <input type="number" class="form-control" id="shift2PinCount" name="shift2PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 2" min=0>
              </td>

              <td>
                    <input type="text" class="form-control" id="shift2Oa" name="shift2Oa" value="222" disabled>
              </td>

              <td>
                    <input type="number" class="form-control" id="shift3PinCount" name="shift3PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 3" min=0>
              </td>

              <td>
                    <input type="text" class="form-control" id="shift3Oa" name="shift3Oa" value="333" disabled>
              </td>

              <td>
                    <input type="number" class="form-control" id="shift4PinCount" name="shift4PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 4" min=0>
              </td>

              <td>
                    <input type="text" class="form-control" id="shift4Oa" name="shift4Oa" value="444" disabled>
              </td>

              <td><input class="form-control" type="date" id="shiftDate" name="shiftDate" value="<?=date("Y-m-d")?>"></td>

              <td>
                <input type="submit" class="btn btn-primary" name="savePcData" id="savePcData" value="savePcData">
              </td> 
</form>
</tr>

<?php

if(isset($_POST['savePcData'])){

    echo "<pre>";
    print_r($_POST);
    die('mms');

}


?> 

Your Out put will be enter image description here

here sourece是您的唯一 ID,可帮助您将数据更新到数据库中

从任何 tr(row) 提交表单后,您将使用 POST 方法重定向到同一页面,并获取该页面上该特定行的数据,以便您可以根据需要轻松更新它

您可以使用 print_r($_POST); 检查这一点在同一页上

如果您有任何疑问,请随时问我...

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

捕获动态表中 HTML 元素的值 的相关文章

  • FPM 与 apache2 无法工作(权限被拒绝)

    我正在尝试使用 apache fastcgi 和 fpm 设置一个 Debian Web 服务器 但我越来越恼火 一旦我停用 mod php 我就会收到以下错误 2014 年 5 月 22 日星期四 12 16 10 错误 客户端 xxx
  • Google Closure 编译器和 multipart/form-data 不起作用

    我正在向 google 闭包编译器 API 服务发出请求 content file get contents file js url http closure compiler appspot com compile post true p
  • MySql 从另一个表中减去一个表

    我有两个表 A 包含所有数据 表 B 从 A 中随机选择 25 的数据创建 所以 A 和 B 具有完全相同的列 也没有独特的列 我想做的是从 A 中减去 B 有什么想法吗 查看所有行A除了那些在B SELECT FROM A WHERE f
  • 如何默认或通过 CSS 将详细信息元素设置为 OPEN

    HTML5 添加了两个新元素 可用于标记文章的目录 details and summary 详细信息元素默认为关闭状态 隐藏除摘要元素之外的所有内容 单击时 它会展开以显示其内容 当它执行此操作时 它会向详细信息元素添加一个 open 属性
  • 平均分配固定大小容器的空间。 Flexbox 的案例?

    如何设计 HTML CSS 结构 将固定大小的容器水平分成三部分 第一部分的高度应与其内容需求一样高 第二部分和第三部分将共享剩余的空间五五十 无论它们的内容如何 如果其内容的大小超过此限制 则该部分应该是可滚动的 它的 HTML 部分很简
  • 从 PHP 启动守护进程

    对于网站 我需要能够启动和停止守护进程 我目前正在做的是 exec sudo etc init d daemonToStart start 守护进程已启动 但 Apache PHP 挂起 做一个ps aux透露sudo它本身变成了僵尸进程
  • 保证金如何运作?

    我在下面提供了marginfix这是一个块级元素并且one and two也是块级的 但它们是浮动的 这就是为什么它们位于同一行布局的原因 但是marginfix也不浮动 块级元素应位于该元素下方 如下所示
  • 如何编写 bash 函数来包装另一个命令?

    我正在尝试编写一个函数包装器mysql command If my cnf存在于 pwd 中 我想自动附加 defaults file my cnf到命令 这就是我正在尝试的 function mysql if e my cnf then
  • 如何将焦点设置在 BootStrap 中的第一个输入字段上? [复制]

    这个问题在这里已经有答案了 可能的重复 如何将焦点设置到独立于 id 的 HTML 表单中的第一个输入元素 https stackoverflow com questions 277544 how to set the focus to t
  • @fontface - 禅宗购物车中的 403 禁止错误

    我不确定这是否是发布此内容的正确位置 因为我不知道问题出在哪里 基本上 字体现在对我来说真的很痛苦 而且没有任何效果 我尝试从 google fonts 加载字体 但遇到了 IE 问题 所以我决定下载它们并自己提供服务 但现在它无法在任何浏
  • django 模板上的 vscode html 自动套用格式

    我喜欢 VSCode 的保存自动格式功能 直到它弄乱了我的模板代码 它错误地将我的 django 模板语法格式化为一行代码 有时非常长的一行 所以不用这段代码 for row in ABCDEFGH tr for col in 123456
  • php - 重定向ajax请求[关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 如何在 php wordpress 中重定向 ajax 请求 I tried header Location http redirect
  • 有没有办法只安装mysql客户端(Linux)? [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 有没有不需要安装整个mysql db安装包的Linux mysql命令行工具 我想做的是从服务器 1 应用程序服务器 执行将在服务器 2
  • MySQL 选择第一个字符在哪里

    如何选择单元格的第一个字符并使用它来定义返回的内容 看看MySQL 字符串 和 控制流 功能 http dev mysql com doc refman 5 1 en functions html 例如 SELECT IF LEFT myF
  • 如何在没有 SSH 和 CLI 访问生产的情况下部署 symfony 项目 [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 大多数托管提供商仅具有 FTP 访问权限 是否可以 常见地进行 symfony 项目 3 x 或 4 x 的本地安装 然后通过 FTP 上
  • Laravel 5 Eloquent 在多个级别上将关系附加到 JSON

    因此 在模型中包含关系非常容易 例如 class User extends Model protected with roles class Role extends Model protected with permissions 当有对
  • 如何告诉node.js mysql没有在默认端口上运行?

    我遇到了与此人类似的问题 连接 ECONNREFUSED 节点 js sql https stackoverflow com questions 8825342 connect econnrefused node js sql 我正在尝试将
  • 如何计算一行中Flexbox项目的数量?

    网格是使用 CSS flexbox 实现的 Example http jsbin com jumosicasi edit html css js output 本示例中的行数为 4 因为我出于演示目的固定了容器宽度 但是 实际上 它可以根据
  • 将 docker-compose.yml 中的包安装到 docker 容器中

    我是 docker 和 docker compose 的初学者 我需要你的帮助 我正在使用 docker compose 制作 PHP NGINX PostgresQL symfony 开发环境 这里是 web image nginx 1
  • 将 Hbase 与 PHP 集成 [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我已经安装了 Hbase 现在我正在寻找一些 PHP 库来将 hbase 与 PHP 集成 我尝试了 2 个库 第一个是我尝试与 th

随机推荐