I did something similar recently. Basically I have one MySQL field to
handle several dozen checkboxes, my situation though was where the
checkboxes are numerically sequential though so I am not sure if this
helps. I also had only a couple hours to do this from start to finish
so I am sure there is a better way, but maybe this helps.
I wrote a function that generates the row of checkboxes, then a
function that combines them all into one field and so the status of
every checkbox is in one field.
Function generates the checkboxes and checks in the array if that
checkbox is checked or not.
function row_generator($row,$number,$array)
{
echo "\n<tr>";
echo "\n\t<th align=\"center\" valign=\"top\">Row $row</th>";
$i = 1;
while ($i <= "$number")
{
if ($i < "10")
{ $row_number = "{$row}-0{$i}"; }
else
{ $row_number = "{$row}-{$i}"; }
echo "\n\t<td align=\"center\" valign=\"top\">";
echo "<input type=\"checkbox\" name=\"$row_number\" id=\"$row_number
\"";
if (strstr($array,$row_number) === FALSE)
{ echo ""; }
else
{ echo " CHECKED"; }
echo ">";
echo "<br>";
echo $i;
echo "</td>";
$i++;
}
echo "\n</tr>";
}
In use:
$seats = $row['seats'];
row_generator("A","23",$seats);
Collect the posted Data and then later this gets input into a database
$poster_A = "";
$i = 1;
while ($i <= "30")
{
if ($i < "10")
{ $r = "0{$i}"; }
else
{ $r = $i; }
if (isset($_POST["A-$r"]))
{ $poster_A .= "A-$r";
$poster_A .= ":"; }
$i++;
}
$seats = ("{$poster_A}{$poster_B}.... etc");
$query = "UPDATE seating_chart SET
seats = '$seats'
WHERE season = '2006'";
--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326
On May 17, 2006, at 11:21 AM, Rahul S. Johari wrote:
Ave,
I’m a little confused as to what’s the best way to handle this.
I have a form which, apart from lots of other fields, has a set of
25 – 30
Check Boxes, each of which asks the user for some kind of
information which
the user can check or leave unchecked.
The information each Check Box collects will also appear in the
“Listing”
for users to view once the user has completed & submitted the form.
Furthermore, there is an Advanced Search also available to users
which will
also provide the same 25 - 30 check boxes which define the search
criteria.
I’m not sure what’s the best, most efficient way to do this.
The tedious way to do this is to make 30 fields in the mySQL
database, and
if the check box is checked, the data goes into the corresponding
field...
And similarly listing the data from the field if field is non-
empty.... And
similarly including each field in the Search options.
I want suggestions for a better/faster way to do this. I did think
about
creating a single field and storing the data from each ‘checked’
check box
as comma separated values in the single field. I’m not sure how to
do that
and if that’s the best way.... But even if I can, I’m not sure how
to get
the data to display separately out of that field in the Listings
view and
more importantly how to include that data in the Search options.
Any help would be appreciated.
Thanks,
Rahul S. Johari
Coordinator, Internet & Administration
Informed Marketing Services Inc.
500 Federal Street, Suite 201
Troy NY 12180
Tel: (518) 687-6700 x154
Fax: (518) 687-6799
Email: rahul@xxxxxxxxxxxxxxxxxxxx
http://www.informed-sources.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php