问题
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/
What I am trying to understand is if it is possible to save the responses from each of the dropdowns
to an Array. 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?
回答1:
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.
来源:https://stackoverflow.com/questions/18672196/php-save-selected-options-from-multiple-drop-downs-to-an-array