Reply to Re: multiple checkboxes

Your name:

Reply:


Posted by kenoli on 12/04/06 20:11

For storing the data, I use a linking table. Thus I have a lookup
table that has the names of my checkboxes in one column, with another
column with unique IDs for each checkbox name. Then I have a linking
table where I have one column for CHECKBOX IDs and the other for PERSON
IDs (assuming you are associating the checkbox names with people).
Thus if a person were identified with 6 different checkboxes, there
would be 6 PERSON ID rows in the linking table associated with each
CHECKBOX ID associated with the appropriate checkbox name.

There are several reasons for doing this:

1. Your person table doesn't get clogged up with a bunch of fields

2. You can change the checkbox names with screwing up existing data.

3. You can easily retrieve the information using joins or other
apporpiate query.

When I display the checkboxes in the form, I do it with the code shown
below. This script gets the checkbox names from the checkbox table and
displays them in an array in a table cell, adding a new cell whenever
it needs to to create a new column. This is set up for 3 columns. You
can change the code for various numbers of columns depending on how
many checkboxes you have.

If you want to show which checkboxes have been checked for which person
IDs, you can derive that data by selecting the checkbox IDs on the
appropriate person ID from the linking table and using that information
to get the names of the checked checkboxes from the checkbox table and
then inserting that between the checkbox tags in the html using
$_POST[].

--Kenoli

//::::::::::::::: Create interest area checkboxes. :::::::::::::::::://

<?php
function interest_checkboxes() {

echo "<fieldset class='callborder'><legend class=\"title\">Interest
Area</legend>\n";

echo "<table class=\"callborder\"><tr>\n<td>";

global $row;

$query = "SELECT * FROM tlu_interest_area ORDER BY interest_area
ASC";
$result = @mysql_query($query);
$number = mysql_num_rows($result);

$i=0;
$second_col = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
if ($i > ($number/3) && $second_col == 0) {
echo "</td><td>";
$second_col = 1;
}
elseif ($i > (2*$number/3) && $second_col == 1) {
echo "</td><td>";
$second_col = 2;
}

if (in_array('6', $interest)) {$checked = 'checked';} else {$checked
= '';}

echo "<input class=\"checkbox\" type=checkbox $checked
name=\"interests[]\" value=\"{$row[interest_area_id]}\"
/>{$row[interest_area]}</input><br/>\n";
$i ++;

}

echo "</td></tr></table></fieldset>";

}

?>

larry@portcommodore.com wrote:
> Gaga wrote:
> > 1.) what is the best way to store multiple checkboxes into table. (e.g. if
> > you 20 checkboxes there is no reason to make 20 table fields ? )
> >
> > 2.) How to pull this stored checkbox data so i can display which checkboxes
> > are checked and which not ?
>
> This is what I had come up with, using arrays when in the script and
> varchar in the DB, you get all the related boxes into one field, and
> have human readable represntation of the contents.
>
> Here's the linik:
>
> http://www.portcommodore.com/quickpage.php?id=mixed+selection+lists
>
> (this page is a work in progress, sorry for any errors)
>
> Larry

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация