Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am stuck with a piece of code that i can't resolve.

I have an Entity, having some arguments. One of them is an Array.

I would like to display it in a Form as several <select> tags.

For instance, my array is called param and $param = array (a,b,c), i would like to get a html form like

 <select name='param[0]'>
      <option value='0'>0</option>
      <option value='1'>1</option>
      <option value='2'>2</option>
    </select>
    <select name='param[1]'>
      <option value='0'>0</option>
      <option value='1'>1</option>
      <option value='2'>2</option>
    </select>
    <select name='param[2]'>
      <option value='0'>0</option>
      <option value='1'>1</option>
      <option value='2'>2</option>
    </select>

Then, at the from subsmission, i would like the $param array to be inserted in the database as an array.

I have try to use de Collection type, but i couldn't resolve it. Thanks for your help !

share|improve this question
add comment

1 Answer

I think it would be much better to use 3 columns instead of arrays.

This way you store value for each of your select elements in a separate column.

share|improve this answer
 
Hi, yes, but i forgot to say that I chose an array representation because the length may vary. –  Pierrito Jul 20 '13 at 18:04
 
How much does it vary? –  zoran404 Jul 20 '13 at 18:15
 
ideally it may vary from 1 to 99 :) –  Pierrito Jul 20 '13 at 18:19
 
In that case array would be better. I see that you have values like 0,1,2, so I think VARBINARY could work for you. Try it out. –  zoran404 Jul 20 '13 at 22:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.