I have created a form that allows a user to enter data, they also have the option to dynamically add more text boxes using JavaScript to provide more information if necessary. e.g. First Name, Last Name, Course. A user may only have one course or they may have many. For every course a user includes I want to be able to store an entire new row in the database. Is there a way I can do this?
关注
码龄 粉丝数 原力等级 --
- 被采纳
- 被点赞
- 采纳率

已采纳
在foreach循环php中存储数据
收起
- 写回答
- 好问题 0 提建议
- 关注问题
微信扫一扫
点击复制链接分享
- 邀请回答
- 编辑 收藏 删除 结题
- 收藏 举报
1条回答 默认 最新
- 关注
码龄 粉丝数 原力等级 --
- 被采纳
- 被点赞
- 采纳率
ds2010630 2015-01-05 04:20关注Welcome to StackOverflow :)
You can do this for sure, but you need to pass every dataset to php. There you can store the data.
<input type="text" name="name1"><input type="text" name="gender1"> <input type="text" name="name2"><input type="text" name="gender2">
And write it to the db in php
for($i = 1; isset($_POST['name' . $i]); $i++) { $name = $_POST['name' . $i]; $gender = $_POST['gender' . $i]; // update DB with input values }
After that you have several new rows inserted.
Alternatively you could create an array for all data:
<input type="text" name="name[]"> <input type="text" name="gender[]">
In PHP, you have to do following
$cnt = count($_POST['name']); for($i=0;$i<$cnt;$i++){ // do any update with database }
本回答被题主选为最佳回答 , 对您是否有帮助呢? 本回答被专家选为最佳回答 , 对您是否有帮助呢? 本回答被题主和专家选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏举报微信扫一扫
点击复制链接分享
编辑预览轻敲空格完成输入- 显示为
- 卡片
- 标题
- 链接
评论按下Enter换行,Ctrl+Enter发表内容
编辑
预览

轻敲空格完成输入
- 显示为
- 卡片
- 标题
- 链接
报告相同问题?
提交
- 2019-04-27 02:06回答 2 已采纳 It seems that you are using Magento and want to retrieve simple products of configurable products.
- 2014-01-06 09:09回答 3 已采纳 Create a new array, fill it: $array = array("v1", "v2", "v3", "v4"); $newArray = array(); forea
- 2019-01-08 21:59回答 1 已采纳 Within loop use get_field function to get the image. check below code for your reference. $imag
- 2020-10-22 21:52这是由于foreach循环在设计时就考虑了对数组的引用和修改,以便在遍历时能够保持数据的一致性。 此外,foreach不仅可以用来遍历数组,还能够用来遍历对象。当遍历对象时,PHP会在对象内部搜索所有可访问的公共、受...
- 2018-01-03 02:59回答 1 已采纳 Try using array_merge_recursive when merging the pieces array, as array_merge will override the ke
- 2017-04-11 12:26回答 1 已采纳 One solution that comes to mind is using array_chunk() to break $rmobiles into multiple arrays wit
- 2018-12-21 11:25回答 1 已采纳 I'm not sure what your original code was trying for; you appeared to be treating the array key lik
- 2020-12-17 23:50在ThinkPHP中,可以使用`foreach`配合模型的`select()`方法来循环输出数据: ```php $Model = M('YourTable'); $data = $Model->select(); foreach ($data as $row) { echo "ID: " . $row['id'] . ", Name: " . $...
- 2017-01-06 11:42回答 1 已采纳 <?php foreach($patchData1 as $tes){ ?> <tr class="<?php if(checkfunction
- 2018-01-23 23:53回答 1 已采纳 Try this : foreach ($parts as &$part) This will be passed by reference, but until now you were do
- 2019-04-16 09:15回答 2 已采纳 try this solution: function array_unique_multidimensional($array, $key) { $temp_array = array
- 2020-12-19 13:14在PHP编程中,当处理大量数据时,一次性加载所有数据可能导致内存耗尽,尤其是在使用循环结构如`foreach`遍历数据库记录时。标题和描述中提到的问题是由于尝试一次性加载4万条数据到内存,超过了PHP允许的最大内存...
- 2021-03-24 01:52薛萤屿的博客 刚开始的时候我用的两个foreach实现这个功能了,但是数据量太大了,一次执行的结果就是内存不够用,直接 504 Gateway Time-out 错误。数据库中只插入了1800多条数据,剩余的数据就没有插入了。现在就是想寻求一种...
- 2020-12-19 08:33函数的主要逻辑在于`foreach`循环,它遍历`$_gPOST`数组中的每一个元素。如果元素是数组,`getPostLog()`函数会递归调用自身,处理子数组并将结果添加到结果数组`$_rs`中。如果元素不是数组,它将键和值直接添加到`$...
- 2020-12-18 12:42在PHP开发中,当需要处理涉及多个数据库表的数据时,批量查询可以显著提高效率。本文将详细介绍如何使用PHP结合mysqli扩展来批量查询多张表的数据。主要涉及的关键知识点包括: 1. **数据库连接**: - 使用`new ...
- 没有解决我的问题, 去提问
联系我们(工作时间:8:30-22:00)
400-660-0108kefu@csdn.net在线客服
- 京ICP备19004658号
- 经营性网站备案信息
公安备案号11010502030143
- 营业执照
- 北京互联网违法和不良信息举报中心
- 家长监护
- 中国互联网举报中心
- 网络110报警服务
- Chrome商店下载
- 账号管理规范
- 版权与免责声明
- 版权申诉
- 出版物许可证
- ©1999-2025北京创新乐知网络技术有限公司