[英]PHP Save selected options from Multiple Drop Downs to an Array
I have the following code: 我有以下代码:
<select id='rq1' class='business' name='q1'>
<option value='1'>1</option>
<option value='2'>2</option>
</select>
<select id='rq2' class='business' name='q1'>
<option value='1'>1</option>
<option value='2'>2</option>
</select>
<select id='rq3' class='business' name='q1'>
<option value='1'>1</option>
<option value='2'>2</option>
</select>
Fiddle: http://jsfiddle.net/NMQz8/ 小提琴: http : //jsfiddle.net/NMQz8/
What I am trying to understand is if it is possible to save the responses from each of the dropdowns
to an Array. 我想了解的是,是否可以将每个
dropdowns
的响应保存到数组中。 The reason for this is so that I can save the results into one column in the database as opposed to having a column for each dropdown response. 这样做的原因是,我可以将结果保存到数据库的一列中,而不是每个下拉响应都有一列。 Does that make sense?
那有意义吗?
Is this possible, is it as straightforward as adding []
to the name and then unserializing
them to post
to the database? 这是否可能,是否像在名称中添加
[]
然后将它们反unserializing
以post
到数据库一样简单?
Do you mean 你的意思是
<?php
var_dump($_POST);
?>
<form method='post'>
<select id='rq1' class='business' name='q1[]'>
<option value='1'>1</option>
<option value='2'>2</option>
</select>
<select id='rq2' class='business' name='q1[]'>
<option value='1'>1</option>
<option value='2'>2</option>
</select>
<select id='rq3' class='business' name='q1[]'>
<option value='1'>1</option>
<option value='2'>2</option>
</select>
<input type='submit'>
</form>
When you submit the form, you will get data in Array. 提交表单时,您将在Array中获取数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.