Entry
How to write multi-selection form data into database field?
Feb 11th, 2005 05:01
Stoyan Stefanov, Dorothy Ryan,
You can comma-separate the values and write them into a text field.
After that when retrieving the data back you have to parse the
comma-separated values. implode() and explode() are two handy functions
for this purpose.
So let's say you have the form
<select name="choices[]" multiple="true" size="3">
<option>1</option>
<option>2</option>
...
</select>
If you post the form you'll have $_POST['choices'] as an array. Before
saving to the database you do:
$one_field_value = implode(',',$_POST['choices']);
...and you're done.
If you need the array back from the database, you
$array_of_choices = explode(',',$database_value);