multiple select/menu in a form, i use implode .....i have a problem

multiple select/menu in a form, i use implode .....i have a problem

am 04.02.2006 23:52:39 von Jim

hey guys and gals,
here is my problem:
i have a form, and recently my crazy mind decided to make 5 select/menus
that belong to the same field ("features"),(each select/menu has many
options, that is why i chose the select menu not, an another way)

SO: the options for "features" field are let us say: (menu value)

smart 1, happy 2, crasy 3 , depressed 4, frustrated 5, lazy 6, dumb 7

now, the user has to choose 4 from them,

So: i made 5 select/menus to select from (each one at a time)

so far so good, if u are still reading, am impressed and i really thank you
:)


now here is what i did:
i named every select/menu "features[]"
and i used implode to get the values to a variable $all like this:

$all = implode(",", $HTTP_POST_VARS['features']);


i succeeded to have the value ( for my example) 0,0,0,0,5,0,0
now i want to get the value of $all in the database, (so i can spit it out
later with an "echo" or something)
i made a field in the database with ENUM, with the "list" inserted in it
sequetially

Question: am i doing it right, what am i doing wrong, and where can i go
from there?

if u have a better suggestion please do not hesitate to suggest with some
"code"

thanks
Jim

Re: multiple select/menu in a form, i use implode .....i have a problem

am 05.02.2006 00:54:29 von zeldorblat

Jim S. wrote:
> hey guys and gals,
> here is my problem:
> i have a form, and recently my crazy mind decided to make 5 select/menus
> that belong to the same field ("features"),(each select/menu has many
> options, that is why i chose the select menu not, an another way)
>
> SO: the options for "features" field are let us say: (menu value)
>
> smart 1, happy 2, crasy 3 , depressed 4, frustrated 5, lazy 6, dumb 7
>
> now, the user has to choose 4 from them,
>
> So: i made 5 select/menus to select from (each one at a time)
>
> so far so good, if u are still reading, am impressed and i really thank you
> :)
>
>
> now here is what i did:
> i named every select/menu "features[]"
> and i used implode to get the values to a variable $all like this:
>
> $all = implode(",", $HTTP_POST_VARS['features']);
>
>
> i succeeded to have the value ( for my example) 0,0,0,0,5,0,0
> now i want to get the value of $all in the database, (so i can spit it out
> later with an "echo" or something)
> i made a field in the database with ENUM, with the "list" inserted in it
> sequetially
>
> Question: am i doing it right, what am i doing wrong, and where can i go
> from there?
>
> if u have a better suggestion please do not hesitate to suggest with some
> "code"
>
> thanks
> Jim

Why not have a single select list that allows multiple selections?
Write your multiple="multiple">. Now the user can select more than one. On the
page where you process the form, $_POST['features'] will be an array
containing each of the selections (like you had before).

I wouldn't implode the list before putting it in your database.
Instead you should normalize things as follows:

A table user (uid, name, etc.)
A table features (fid, name, etc)
A table userFeatures (uid, fid)

This does two things. To indicate that a user made a selection, insert
a row in userFeatures with the user's uid and the feature's fid. This
also gives you a list of the choices in your database somewhere so you
don't need to hard-code them on the pages to make the select lists.

Re: multiple select/menu in a form, i use implode .....i have a problem

am 05.02.2006 00:54:36 von Shion

Jim S. wrote:
> hey guys and gals,
> here is my problem:
> i have a form, and recently my crazy mind decided to make 5 select/menus
> that belong to the same field ("features"),(each select/menu has many
> options, that is why i chose the select menu not, an another way)
>
> SO: the options for "features" field are let us say: (menu value)
>
> smart 1, happy 2, crasy 3 , depressed 4, frustrated 5, lazy 6, dumb 7
>
> now, the user has to choose 4 from them,
>
> So: i made 5 select/menus to select from (each one at a time)
>
> so far so good, if u are still reading, am impressed and i really thank you
> :)
>

Why not make it simple to make one multiselect list




> i succeeded to have the value ( for my example) 0,0,0,0,5,0,0
> now i want to get the value of $all in the database, (so i can spit it out
> later with an "echo" or something)
> i made a field in the database with ENUM, with the "list" inserted in it
> sequetially

Say your list gets longer and you have 15 to select from, and you want to look
for say five (5), you will get more trouble with your search query as the five
could be the first, last or somewhere in the middle, you need to think about
the commas as you can search fro just '%5%' as this would return the users who
has selected 15.

This makes it a lot more difficult to search IMHO, I would rather have a table
where I save the userid and the value where the userid+value is the key (to
prevent multiples of the same result in the table).



//Aho

Re: multiple select/menu in a form, i use implode .....i have a problem

am 05.02.2006 03:26:07 von Jim

well J.O. Aho i thought about the multiselect, but the problem is , i
have so many options, but i want only 4 or 5 to be selcted, and i do not
know how to limit the multi select to just 4 or 5 (out of let us say 10)

furthermore, the select/menu is part of a bigger form, and am afraid that
"multi select could confuse the PP out of them ;)

do u have any note on, can i store an array in a database? and how?
code please if it is not too much trouble :D
thanks again
Jim

> Why not make it simple to make one multiselect list
>
>
>
>
>> i succeeded to have the value ( for my example) 0,0,0,0,5,0,0
>> now i want to get the value of $all in the database, (so i can spit it
>> out later with an "echo" or something)
>> i made a field in the database with ENUM, with the "list" inserted in
>> it sequetially
>
> Say your list gets longer and you have 15 to select from, and you want to
> look for say five (5), you will get more trouble with your search query as
> the five could be the first, last or somewhere in the middle, you need to
> think about the commas as you can search fro just '%5%' as this would
> return the users who has selected 15.
>
> This makes it a lot more difficult to search IMHO, I would rather have a
> table where I save the userid and the value where the userid+value is the
> key (to prevent multiples of the same result in the table).
>
>
>
> //Aho

Re: multiple select/menu in a form, i use implode .....i have a problem

am 05.02.2006 03:33:24 von Jim

sorry ZeldoreBlat, i did not mean to neglect u, but the same response that i
said to J.O. applies here to.

"ZeldorBlat" wrote in message
news:1139097269.517377.257710@f14g2000cwb.googlegroups.com.. .
>
> Jim S. wrote:
>> hey guys and gals,
>> here is my problem:
>> i have a form, and recently my crazy mind decided to make 5 select/menus
>> that belong to the same field ("features"),(each select/menu has many
>> options, that is why i chose the select menu not, an another way)
>>
>> SO: the options for "features" field are let us say: (menu value)
>>
>> smart 1, happy 2, crasy 3 , depressed 4, frustrated 5, lazy 6, dumb 7
>>
>> now, the user has to choose 4 from them,
>>
>> So: i made 5 select/menus to select from (each one at a time)
>>
>> so far so good, if u are still reading, am impressed and i really thank
>> you
>> :)
>>
>>
>> now here is what i did:
>> i named every select/menu "features[]"
>> and i used implode to get the values to a variable $all like this:
>>
>> $all = implode(",", $HTTP_POST_VARS['features']);
>>
>>
>> i succeeded to have the value ( for my example) 0,0,0,0,5,0,0
>> now i want to get the value of $all in the database, (so i can spit it
>> out
>> later with an "echo" or something)
>> i made a field in the database with ENUM, with the "list" inserted in
>> it
>> sequetially
>>
>> Question: am i doing it right, what am i doing wrong, and where can i go
>> from there?
>>
>> if u have a better suggestion please do not hesitate to suggest with some
>> "code"
>>
>> thanks
>> Jim
>
> Why not have a single select list that allows multiple selections?
> Write your > multiple="multiple">. Now the user can select more than one. On the
> page where you process the form, $_POST['features'] will be an array
> containing each of the selections (like you had before).
>
> I wouldn't implode the list before putting it in your database.
> Instead you should normalize things as follows:
>
> A table user (uid, name, etc.)
> A table features (fid, name, etc)
> A table userFeatures (uid, fid)
>
> This does two things. To indicate that a user made a selection, insert
> a row in userFeatures with the user's uid and the feature's fid. This
> also gives you a list of the choices in your database somewhere so you
> don't need to hard-code them on the pages to make the select lists.
>

Re: multiple select/menu in a form, i use implode .....i have a problem

am 06.02.2006 15:29:17 von zeldorblat

Jim S. wrote:
> well J.O. Aho i thought about the multiselect, but the problem is , i
> have so many options, but i want only 4 or 5 to be selcted, and i do not
> know how to limit the multi select to just 4 or 5 (out of let us say 10)
>
> furthermore, the select/menu is part of a bigger form, and am afraid that
> "multi select could confuse the PP out of them ;)
>
> do u have any note on, can i store an array in a database? and how?
> code please if it is not too much trouble :D
> thanks again
> Jim

There's an easy way to put arrays into the database, albeit not the
greatest. But you seem to be interested in easy:

$a = array('foo', 'bar', 'baz');
$s = serialize($a); //$s is a string

//Insert $s into some text field in your database

//Get the string out of the database into, say, $x
$a = unserialize($x); //$a is an array again