Another newbie checkbox question
| From: | Rob Costain | Date: | Mon, 05 May 2003 18:03:44 +0000 |
| Subject: | Another newbie checkbox question | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-27539@lists.php.net to get a copy of this message | ||
I have a database with a listing called "schools" (table 1) and a list of
categories called "highlights" to be assigned to each school (table 2).
Each school in the list can have multiple highlights, so I am using
checkboxes on my editing form. The checkboxes are generated by looping
through the "highlights" table.
<CODE SAMPLE>
<?php
// Fetch the list of highlights from the database.
while ($numrows = mysql_fetch_array($highlight_select)) {
echo "<input type=\"checkbox\" name=\"highlight_submit[]\"
value=\"".$numrows[highlight]."\"> ".$numrows[highlight]."<br>\n";
}
?>
</CODE SAMPLE>
I plan to store the contents of the checkboxes in an array, and them implode
it into a single field/column called "highlights" in the "schools" table
separated by commas.
<CODE SAMPLE>
$highlights.schools = implode(", ", $highlight_submit);
</CODE SAMPLE>
My problem? When a user accesses the form, I want them to be able to see if
any highlights are already checked off. I query the highlights field in the
schools table and explode it into an array.
<CODE SAMPLE>
$highlight_checked = explode(", ",$schoolinfo[highlights]);
</CODE SAMPLE>
I want to test the checkboxes against the contents of the exploded array,
but I can't seem to figure out the logic. When I've gotten the boxes to be
checked, I get doubles or triples of the same checkbox.
Should I write a separate function to handle the test, or can I nest a loop
in the WHILE loop that generates the checkboxes in the first place?
This is a simple problem (I think), but it has me very confused!
TIA,
Rob
--
Rob Costain
rcostain@sympatico.ca - 514.808.3639
Quebec English Schools Network RÉCIT - http://www.qesnrecit.qc.ca