checkboxes redux
| From: | Adv. Systems Design | Date: | Mon, 02 Oct 2000 20:11:21 +0000 |
| Subject: | checkboxes redux | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-3234@lists.php.net to get a copy of this message | ||
Here goes 2nd try...
I have a table with prerequisites and another with the
lessonID and PreqID (lesson_preq)...what I need to do
is list all checkboxes from the preq table and
"CHECKED" all the matching values in the lesson_preq,
to give the user the opportunity to modify the
prerequisites associated with the lesson (on a
form)...the code below does what I want (I finally
figured out the nesting), BUT it has a bug...if there
are 3 prerequisites for that lesson, it prints each
prerequisite 3 times...All I want is for it to print
all preqs once, and check the ones that should be
checked.
I know I am making a STUPID NEWBIE ASS MISTAKE, but
can someone please point it out?!
CODE:
<?
$prq = db_query("
SELECT preq_id, prereq
FROM preqs
ORDER BY preq_id ASC
");
If ($prq) {
while ($allprq = db_fetch_array($prq)) {
/* get all prerequisites */
$lsnprq = db_query("
SELECT preq_id
FROM lesson_preq
WHERE l_id = $id
");
if ($lsnprq) {
while ($lessonprq = db_fetch_array($lsnprq)) {
/* get lesson prerequisites */
$checked = ''; //clear var
if ($allprq['preq_id'] == $lessonprq['preq_id']) {
/* if the preq has a match in lesson_preq, set the
value */
$checked = ' CHECKED';
}
//prints all of them correctly but repeats ea preq #
times for checked preqs
echo ("<INPUT TYPE=checkbox NAME=preq[]
VALUE=\"".$allprq['preq_id']."\"".$checked.">".$allprq['prereq']."<BR>\n");
}
}
}
}
?>
__________________________________________________
Do You Yahoo!?
Yahoo! Photos - 35mm Quality Prints, Now Get 15 Free!
http://photos.yahoo.com/