Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 135,914 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,585 people online right now. Registration is fast and FREE... Join Now!




Multi-select Box

 
Reply to this topicStart new topic

Multi-select Box

klewlis
19 Sep, 2002 - 07:07 AM
Post #1

cur tu me vexas?
*****

Joined: 9 Nov, 2001
Posts: 1,723

I have a select box like so:

CODE

<select name="Options" size="5" multiple>
...


and I assumed that php would pick that up with commas... but I only get the last item selected, not all of them. Is there a way to make it pick up all of them?
User is offlineProfile CardPM
+Quote Post

fyrestorm
RE: Multi-select Box
19 Sep, 2002 - 07:56 AM
Post #2

D.I.C Lover
Group Icon

Joined: 4 Apr, 2002
Posts: 3,103



Thanked: 2 times
Dream Kudos: 228
My Contributions
hmmm, i've never done that before, but i have an idea, i'll post back in a moment...

edit: actually, i have done that before make your name options[] that way it's an array...
User is offlineProfile CardPM
+Quote Post

klewlis
RE: Multi-select Box
19 Sep, 2002 - 09:37 AM
Post #3

cur tu me vexas?
*****

Joined: 9 Nov, 2001
Posts: 1,723

no, that doesn't help. But it might be in the processing. I'm using Phorm 3.0 (have any of you used that?) and it does all the processing for me. Thousands of lines of code... I can't find the part where it deals with those variables... *sigh*

Any other ideas?
User is offlineProfile CardPM
+Quote Post

fyrestorm
RE: Multi-select Box
19 Sep, 2002 - 11:01 AM
Post #4

D.I.C Lover
Group Icon

Joined: 4 Apr, 2002
Posts: 3,103



Thanked: 2 times
Dream Kudos: 228
My Contributions
hmmm, i'm gonna have to poor over some code, give me a few, cause i know it can be done, i've done it before, i just have to see where i did it...
User is offlineProfile CardPM
+Quote Post

Quik
RE: Multi-select Box
19 Sep, 2002 - 11:07 AM
Post #5

D.I.C Lover
Group Icon

Joined: 6 Mar, 2001
Posts: 3,750



Thanked: 1 times
My Contributions
I believe each entry is stored in a array that you specify. In your case

$options[x]


Edit
just saw fyrestorms post. Maybe not, but thats how I remember it to be
User is offlineProfile CardPM
+Quote Post

fyrestorm
RE: Multi-select Box
19 Sep, 2002 - 11:19 AM
Post #6

D.I.C Lover
Group Icon

Joined: 4 Apr, 2002
Posts: 3,103



Thanked: 2 times
Dream Kudos: 228
My Contributions
QUOTE(Quik @ Sep 19 2002, 01:07 PM)
I believe each entry is stored in a array that you specify. In your case

$options[x]



just saw fyrestorms post. Maybe not, but thats how I remember it to be

you're absolutely right quik, let me help her out a little (or at least try to)

------------------------------

ok here's how it works you have your select box that has the name options[]
when they select their items it fills the array, so here's a couple things you need to do:
1) what's the max num of items they can select?
2) what are you doing with that data?

once you know that, you can extract the data by running a for loop

from what you said i'm gonna assume that you want the data comma separated

CODE

$data ="";  // to hold data

for($i=0, $i <= $max, $i++) {
  $data .= "$options[$i],";
}
// the .= operator concatenates what's in the i'th cell of options to what's already in data, so you'll get  'something, something, something' which is what i think you want


let me know if that's not what you need.
User is offlineProfile CardPM
+Quote Post

klewlis
RE: Multi-select Box
19 Sep, 2002 - 11:25 AM
Post #7

cur tu me vexas?
*****

Joined: 9 Nov, 2001
Posts: 1,723

actually it's simpler to do this:

CODE

if (count($Options) >1) {
  $Options = join(", ", $Options);
 }


which works perfectly.

And for future reference, if any of you are using Phorm, you can put that snippet right into your individual config file and it will process it... (rather than trying to find it in phorm.php....).

Thanks for the help.
User is offlineProfile CardPM
+Quote Post

Quik
RE: Multi-select Box
19 Sep, 2002 - 11:27 AM
Post #8

D.I.C Lover
Group Icon

Joined: 6 Mar, 2001
Posts: 3,750



Thanked: 1 times
My Contributions
even easier.
A one line solution to the above would be


$array = array('one', 'two', 'three');
$list = implode(",", $array);


now, $list equals "one,two,three"
User is offlineProfile CardPM
+Quote Post

fyrestorm
RE: Multi-select Box
19 Sep, 2002 - 11:28 AM
Post #9

D.I.C Lover
Group Icon

Joined: 4 Apr, 2002
Posts: 3,103



Thanked: 2 times
Dream Kudos: 228
My Contributions
well, we all found solutions, and i think i like quik's best, it's the shortest...hehe
User is offlineProfile CardPM
+Quote Post

klewlis
RE: Multi-select Box
19 Sep, 2002 - 11:31 AM
Post #10

cur tu me vexas?
*****

Joined: 9 Nov, 2001
Posts: 1,723

QUOTE(Quik @ Sep 19 2002, 02:27 PM)
even easier.
A one line solution to the above would be


$array = array('one', 'two', 'three');
$list = implode(",", $array);


now, $list equals "one,two,three"

implode is exactly the same as join :P

i just added the if statement... which might not be necessary...
User is offlineProfile CardPM
+Quote Post

fyrestorm
RE: Multi-select Box
19 Sep, 2002 - 11:35 AM
Post #11

D.I.C Lover
Group Icon

Joined: 4 Apr, 2002
Posts: 3,103



Thanked: 2 times
Dream Kudos: 228
My Contributions
QUOTE(klewlis @ Sep 19 2002, 01:31 PM)
QUOTE(Quik @ Sep 19 2002, 02:27 PM)
even easier.
A one line solution to the above would be


$array = array('one', 'two', 'three');
$list = implode(",", $array);


now, $list equals "one,two,three"

implode is exactly the same as join tongue.gif

i just added the if statement... which might not be necessary...

yeah, i'm thinking that it might be a bit of unnecessary code
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 07:54AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month