Re: checkboxes redux
| From: | burk at pobox dot com | Date: | Tue, 03 Oct 2000 00:32:57 +0000 |
| Subject: | Re: checkboxes redux | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-3240@lists.php.net to get a copy of this message | ||
On Mon, 2 Oct 2000, Adv. Systems Design wrote:
> Here goes 2nd try...
>
Check the loop following your 2nd SQL call. What you want is to move the
echo ("<INPUT TYPE=checkbox NAME=preq[] so that it is in the loop for the
first SQL call. Then the only thing you should echo in the 2nd SQL loop is
"CHECKED" when appropriate. As it is now, since your <INPUT> if being
echoed with each iteration of the 2nd SQL's loop you get a checkbox for
every element in the lesson_preq table that matches the SELECT statement.
That ought to do it, everything else looks basically OK to a quick
examination.
Hope this helps.
-burk
> 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");
> }
> }
> }
> }
> ?>
--
burk@pobox.com
Linux File Managers: http://www.pobox.com/~burk/linuxfile.html