Forum Moderators: coopster

Message Too Old, No Replies

php and form select

Best practice for php selct?

         

joedub

5:29 pm on Dec 14, 2004 (gmt 0)

10+ Year Member



Hello,

<select multiple size="5" name="groups[]">

<option value="1">group 1
<option value="2">group 2
<option value="3">group 3
<option value="4">group 4
<option value="5">group 5

</select>

What is the most efficient way to store these values in a MySql database for later retrieval?

My current way of doing it would involve creating a string from the selected values and using a character to pad them.
e.g "-2-4-"
so then i would try and retrieve them using a query like
"SELECT * FROM table WHERE (field LIKE'%-2-%') OR ('field LIKE'%-4-%')"

Is there a better way to do this?

Salsa

6:49 pm on Dec 14, 2004 (gmt 0)

10+ Year Member



Off hand, I can't think of a much better way to do what you want. If you weren't needing to SELECT by the data, I'd definitely recommend serialize() [us2.php.net], which takes the elements of an array and serializes them into a string for storing in a database TEXT field. You get them back into an array with unserialize(). You could still do that, but try it, and echo out an example of the serialized string so you can see how you'd have to edit your WHERE clause.

I hope this helps.