Another newbie checkbox question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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]."\">&nbsp;".$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 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux