PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 9th, 2012, 11:43 AM
stoyleg stoyleg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2011
Posts: 7 stoyleg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 47 m 14 sec
Reputation Power: 0
PHP5 - 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.

Reply With Quote
  #2  
Old October 9th, 2012, 12:16 PM
Jacques3 Jacques3 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 57 Jacques3 User rank is Sergeant (500 - 2000 Reputation Level)Jacques3 User rank is Sergeant (500 - 2000 Reputation Level)Jacques3 User rank is Sergeant (500 - 2000 Reputation Level)Jacques3 User rank is Sergeant (500 - 2000 Reputation Level)Jacques3 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 10 h 6 m 14 sec
Reputation Power: 11
Hi,

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?

Reply With Quote
  #3  
Old October 9th, 2012, 12:37 PM
stoyleg stoyleg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2011
Posts: 7 stoyleg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 47 m 14 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old October 9th, 2012, 01:59 PM
badger_fruit's Avatar
badger_fruit badger_fruit is offline
Confused badger
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2009
Location: West Yorkshire
Posts: 760 badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 5 h 15 m 18 sec
Reputation Power: 339
Quote:
Originally Posted by stoyleg
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.


Name the menus the same name with [] at the end; for example:-

<select name='mymenu[]'>
<option value=1>1</option>
<option value=2>2</option>
...
<option value=5>5</option>
</select>

<select name='mymenu[]'>
<option value=A>B</option>
<option value=B>B</option>
...
<option value=E>E</option>
</select>


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.
__________________
The number for UK Emergencies is changing, the new number is 0118 999 881 999 119 7253

"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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP5 - Multiple list menus into one database column

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap