php - 单击提交按钮后如何使用 id 获取此名称?
问题描述
下面的代码我使用输入名称结果+行 id 并且它按预期工作。
<td class="t-width-150" id="result">
<input type="text" name="result<?php echo $row['id']; ?>" id="txtresult" value="0">
</td>
现在我想在单击提交按钮后在另一个页面中获取这个带有 id 的名称。我应该在下面的代码中使用什么:
<td class="t-width-150">
<?php echo $_POST['result']; ?>
</td>
谢谢!
更新:我解决了。不需要更多答案。谢谢大家!
解决方案
您可以使用这样的表单字段命名格式:
name="result[<?php echo $row['id']; ?>]"
如此有效,这将导致字段名称如result[1]
, result[2]
, result[5]
(ID 不需要连续或按顺序排列。)
然后,PHP 将在其中生成一个数组$_POST['result']
,您可以使用扩展的 foreach 语法循环访问该数组,以访问您的行 ID 和提交的值:
foreach( $_POST['result'] as $id => $value ) {
echo "The submitted value for the record with ID ", $id, " was ", $value, "<br>\n";
}
推荐阅读
- firebase - 如何在一个项目下创建多个 Vue 应用
- python - 如何将 Dask DataFrame 与 Numpy Busday_count 一起使用?
- xml - Powershell 移动 xml 节点
- elixir - Jason 在 Elixir 中将二进制编码为 UUID
- python - 在 python 中调用 CosmosClient(url,key,proxy_config = d) 时出现错误?
- javascript - 由于引号不同,Array.prototype.filter() 不适用于对象数组
- python - JSONDecodeError:期望值 Python
- python - 在 Python 中将“大”整数转换为字节时遇到问题
- laravel - 一个modelName.php 和一个ModelNameController.php 可以处理多个相同(或相似)的表吗?
- reactjs - 在 Material UI 自动完成中的 Textfield 输入中显示匹配搜索选项的数量