View Full Version : Checkboxes -> Database
Adrian Schneider
03-05-2005, 03:34 PM
How would I go about doing this:
Insert checked checkboxes into database as a set (into text field), the only complication is the # of checkboxes is an unknown, as there is one for every 'player' in the player table (values are IDs). The names of the fields all are: positionXXX (where XXX = playeriD).
Sorry if this is yet another easy question, my brain shuts off sometimes. :rolleyes:
Marco van Herwaarden
03-05-2005, 04:31 PM
You should name your fields as an array ie position[].
Then you can just serialize the array into the database field.
Adrian Schneider
03-05-2005, 04:39 PM
Okay, I set them as position[$id], what do you mean by serialize the array?
Marco van Herwaarden
03-05-2005, 04:47 PM
serialize($position)
Adrian Schneider
03-05-2005, 05:11 PM
Could someone elaborate on this a little for me. Do I create the array first? and do I name them $position[$id] or just position[$id] (if position[$id] how does it know what $position is?)
Marco van Herwaarden
03-05-2005, 05:19 PM
You name the field in your form 'position[]' (or 'position[$id]' if the Id is relevant).
After submit your would do a:
globalize($_POST, array(
'position'
));
.
.
.
<insert/update database>
serialize($position)
Adrian Schneider
03-05-2005, 06:42 PM
Thanks for all the help so far.
2 small problems (I hope): I have a select menu of all the players, I want to restrict the players by only showing results where FIND_IN_SET('$id', fieldname) but I need the $id to be the current $id that mysql is processing, the other problem is, if the id is 1, 11, 21, 108, and 3081, all of these will be included. Is there a way to force X # of digits?
If this makes the first problem easier, the field containing the string of numbers (ex: 1,3,4,25,234234,3563) is in another table, which is selected prior to all of this.
Marco van Herwaarden
03-05-2005, 07:52 PM
Sorry you lost me now.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.