PHP $_POST 值
我在存储 $_POST 数据时遇到了一些问题,我想我可能会让自己有点困惑。
所以我有一些数据从循环中发布,这些数据作为 id 和点发布,但每个数据都有一个数字,所以如果发布三个记录,我们将有
id1、id2、id3 point1、point2、point3
收集 。现在我使用 for 循环来遍历数据并将其发布到两个数组中进行处理。问题是当我想存储数据时,我必须使用上面列出的名称之一,即 id1 或 id2。这是我的代码
for($i = 0; i< $_POST['count']; i++){
//Order input data into an array
$inputid[$i] = $_POST['id1'];
}
现在 $_POST['id1'] 的 'id' 的数字部分必须与 for 循环中的 $i 相同,因此它会随着循环而递增。
感谢您的帮助,我希望我正确地解释了问题。
i have a little problem with storing the $_POST data, think i might be confusing myself a little.
So i have some data being posted from a loop, this data is posted as id and points, but each has a number to it so if three records are being posted we'll have
id1, id2, id3
points1, points2, points3
to collect. Now i'm using a for loop to go through the data and post it into two arrays to work with. The problem is When I want to store the data i have to use one of the names listed above ie id1 or id2. Here is my code
for($i = 0; i< $_POST['count']; i++){
//Order input data into an array
$inputid[$i] = $_POST['id1'];
}
Now the number part of the 'id' of the $_POST['id1'] has to be the same as $i in the for loop so it will increment as the loop does.
Thanks for the help and i hope i explained the question right.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果我理解这个问题,那么已经有已知数量的输入将被发布,所以我不明白为什么你需要一个循环来将它们添加到数组中。为什么不这样做:
比这样循环:
那应该可行
If I understand this question, there are already a known amount of inputs that are going to be posted, so I don't understand why you need a loop at all for adding them to the array. Why not do this:
than loop like this:
That should work
如果我没有出错,你希望发布的 id 与增量 var $i 相同,试试这个
if i am not going wrong you want the posted id same as the increment var $i try this out
我认为你可以这样做:
这是你想要的吗?
I think you can go for something like this:
Is this what you want?
为什么不命名输入:
name="id[1]"
和name="points[1]"
这样你就会有$_POST['id '][...]
和$_POST['points'][...]
数组可以使用吗?参考:来自外部源的变量(特别是示例#3)。
Why not name the inputs:
name="id[1]"
andname="points[1]"
so you'll have$_POST['id'][...]
and$_POST['points'][...]
arrays to work with?Reference: Variables From External Sources (specifically Example #3).
首先,不要在循环或其他任何内容中使用 POST 变量,除非您首先检查了它们以确保它们不包含任何令人讨厌的内容。
你可以在循环中尝试这个:
Firstly, don't use POST variables in loops or anything else unless you've checked them out first to make sure they don't contain anything nasty.
You could try this within the loop:
只需连接索引中的字符串即可:
Simply concatenate the string in the index: