为了账号安全,请及时绑定邮箱和手机立即绑定

从表中动态创建的输入中获取值

从表中动态创建的输入中获取值

PHP
慕森卡 2023-03-04 14:46:32
我有一张桌子   <form id="project-form">                    <table id="project-table" class="table table-striped table-inverse table-responsive">                        <caption>Projects</caption>                        <thead class="thead-inverse">                            <tr>                                <th scope="col">#</th>                                <th scope="col">Project name</th>                                <th scope="col">Description</th>                                <th scope="col">Estimated time (min)</th>                                <th scope="col">Actual time (min)</th>                                <th scope="col">Add task</th>                                <th scope="col">Delete project</th>                            </tr>                        </thead>                        <tbody id="project-body">                        </tbody>                    </table>                </form>此表填充了来自 AJAX GET 请求的数据function getProjects() {  $.ajax({    method: 'GET',    dataType: 'json',    data: {      functionToCall: 'project',    },    url: 'http://localhost/WBS/php/api/requests/get.php',    success: (response) => {      $.each(response, function () {        $.each(this, function (index, value) {          $('#project-body').append(            `            <tr>                <td>                  <input class="form-control" type="hidden" name="projectid" id="projectid"  value="${value.projectid}">                </td>                <td>                  <input class="form-control" type="text" name="projectName" id="projectName" value="${value.title}">                </td>                <td>                  <input class="form-control" type="text" name="description" id="description"  value="${value.description}">                </td>
查看完整描述

1 回答

?
慕村225694

TA贡献1880条经验 获得超4个赞

我认为您可以重命名您的输入,例如:


 name="projectid[]"

然后 PHP 将收到这些值的数组:


$total = count($_POST["projectid"]);

for ($i = 0; $i < $total; $i++) {

    $title = $_POST["projectName"][$i];

    $description = $_POST["description"][$i];

    $estimatedTime = $_POST["estimatedTime"][$i];

    $actualTime = $_POST["actualTime"][$i];


    // Your INSERT query is performed here

}


查看完整回答
反对 回复 2023-03-04
  • 1 回答
  • 0 关注
  • 75 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号