Re: checkboxes names & values in mySQL (newbie)

From: Date: Fri, 11 Oct 2002 07:03:10 +0000
Subject: Re: checkboxes names & values in mySQL (newbie)
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-22336@lists.php.net to get a copy of this message
Here's a nifty trick. Name your check boxes like this. <input type="checkbox" name="myarray[]" value="value1" /> <input type="checkbox" name="myarray[]" value="value2" /> <input type="checkbox" name="myarray[]" value="value3" /> <input type="checkbox" name="myarray[]" value="value4" /> Then when it posts back to php, you will have a nice array. Lets say that they tick all but value2, then you will have: $myarray == array("value1", "value3", "value4"); I guess the order in which they appear is arbitrary, but that makes no matter for a MySQL enum. So just do an implode on the array to put it in the database. Cheers, Owen Prime http://www.noggin.com.au John wrote: > I'm new at using PHP and mySQL, so please forgive my potentially naive > question. > > I have a series of checkboxes with different values. The user can select > any number of checkboxes, and I need to store this information in a mySQL > table. > > 2 questions: > Should I have a unique form name for each checkbox, and store it's boolean > value in the database, OR (is it more streamlined) .. > To create an array <input type=checkbox name=apps value =myarray[$i]> with > the same name but different value for each checkbox. > > Finally, how do I construct the query to store the array of values? Do I > need a separate column (enum('n','y') for each value, or should I store > all the true values as a long text string? > > If anyone has some code snippets, that would help very much. > > Thanks very much!

« previous php.db (#22336) next »