faqts : Computers : Programming : Languages : PHP : Sample Code

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

12 of 19 people (63%) answered Yes
Recently 6 of 10 people (60%) answered Yes


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">
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);