You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CodeIgniter框架:使用复选框批量更新多行数据失败求助

CodeIgniter批量更新多行数据仅单行生效,已尝试现有方案仍未解决

各位大佬好!我在CodeIgniter项目里做一个批量更新功能,通过复选框选中多条数据后提交更新,但不管怎么测试,每次操作都只有单行数据能成功更新。之前因为工作太忙没来得及看大家的回复,现在把能找到的相关解决方案都试了个遍,问题还是没解决。我把当前的表单视图代码贴出来,麻烦各位帮忙排查下问题,给点可行的解决方案,万分感谢!


我的表单视图代码:

<form action="<?php echo base_url('admin/batch_update'); ?>" method="post">
    <table>
        <thead>
            <tr>
                <th><input type="checkbox" id="select_all"> 全选</th>
                <th>数据ID</th>
                <th>状态设置</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($data_items as $item): ?>
            <tr>
                <td><input type="checkbox" name="selected_ids[]" value="<?php echo $item['id']; ?>"></td>
                <td><?php echo $item['id']; ?></td>
                <td>
                    <select name="status[<?php echo $item['id']; ?>]" class="form-control">
                        <option value="0" <?php echo $item['status'] == 0 ? 'selected' : ''; ?>>禁用</option>
                        <option value="1" <?php echo $item['status'] == 1 ? 'selected' : ''; ?>>启用</option>
                    </select>
                </td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
    <button type="submit" class="btn btn-success">执行批量更新</button>
</form>

<script>
// 全选功能实现
document.getElementById('select_all').addEventListener('click', function(e) {
    const checkboxes = document.querySelectorAll('input[name="selected_ids[]"]');
    checkboxes.forEach(checkbox => checkbox.checked = e.target.checked);
});
</script>

内容的提问来源于stack exchange,提问作者courage

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:56:38