Page 1 of 1

checkbox values inserting to mysql

Posted: Thu Dec 14, 2006 10:05 pm
by zyklone
I have a form with checkboxes on it. if the user checks two or more checkboxes i use to compress all values in string format (example: dog|cat|chicken) then thats the time i will store it to my mysql database. it saves my database size coz instead of putting doc, cat, chicken in each row of my table i use to compress it.

is it a good practice? or what other technique to you use? thanks!

Posted: Thu Dec 14, 2006 10:08 pm
by Burrito
make your checkboxes an array then serialize() the array for insertion to the db.

Posted: Thu Dec 14, 2006 11:11 pm
by zyklone
if i use serialize() how can i query it? does the mysql can still find it?

Posted: Thu Dec 14, 2006 11:16 pm
by Burrito
theoretically you 'could' using the like operator, but that's not ideal.

I don't think you're any better off if you want to save them in the same column using a different method, but a cleaner solution would be to use implode() if you're planning on searching on those values...it's cleaner, but still not your 'best' solution.

you have two threads going that are basically asking the same questions.... I'm locking this one and you can continue any further discussions in the other.