October 9th, 2012, 11:43 AM
Multiple list menus into one database column
I have 10 list menus on a page. I want to take the values selected in each menu and insert them, one row at a time, into one mysql column.
I think an array is required, but I don't know how to get values from multiple list menus into and array and then insert these into a database.
Any help much appreciated.
October 9th, 2012, 12:16 PM
Storing an array in a table is a bad idea. It violates the principle of normalization and makes data processing difficult and slow. In MySQL, it isn't even possible without some kind of hack. You'd have to store the values in a string either using a certain data format (like JSON) or comma-separating them.
How did you even get to this requirement? Wouldn't it make more sense to ask about a sensible way of storing the values?
There are basically two possibilities that make sense: If the set of options is fixed and unlikely to change, you could make 10 columns (that's especially useful when you have different data types). Otherwise, create a "key" and a "value" column and store each selection in a separate row.
Apart from those general suggestions, your question is much too vague. We need some specific code/HTML. What did you try already?
October 9th, 2012, 12:37 PM
I do currently have 10 columns, the problem is when I come to do the analysis, the data in those 10 columns need to be put into 1 column grouped by an ID. I can't for the life of me work out how to do this in SQL so thought the simplest way would be to take the values from the 10 list menus and insert them into 1 column.
Maybe this is a query issue rather than PHP.
It's actually hard to explain what it is I'm doing without showing you the forms and expected outputs, examples of which I only have in Excel spreadsheets.
October 9th, 2012, 01:59 PM
Name the menus the same name with  at the end; for example:-
Originally Posted by stoyleg
Then, when submitted, the data is already in an array called, in this case 'mymenu', you can either write that as a lump into MySQL or do a foreach / for loop, inserting one selection at a time.
"For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
- George Orwell, 1984