[PHP-DB] Help - almost got it From: luis <email protected>
Date: 09/28/00

Well, I struggled and almost have it figured out, but I have a problem with
repeating data:
This is a part of the output...it should be that each checkbox only appears
once (and as you can notice, the CHECKED is working!!)
<INPUT TYPE=checkbox NAME=preq[] VALUE="100"
CHECKED>Connecting with WebTV<BR>
<INPUT TYPE=checkbox NAME=preq[] VALUE="100">Connecting with
WebTV<BR>
<INPUT TYPE=checkbox NAME=preq[] VALUE="100">Connecting with
WebTV<BR>
<INPUT TYPE=checkbox NAME=preq[] VALUE="101">Reading
Email<BR>
<INPUT TYPE=checkbox NAME=preq[] VALUE="101">Reading
Email<BR>
<INPUT TYPE=checkbox NAME=preq[] VALUE="101">Reading
Email<BR>
<INPUT TYPE=checkbox NAME=preq[] VALUE="102">Addressing
Email<BR>
<INPUT TYPE=checkbox NAME=preq[] VALUE="102"
CHECKED>Addressing Email<BR>
<INPUT TYPE=checkbox NAME=preq[] VALUE="102">Addressing
Email<BR>
<INPUT TYPE=checkbox NAME=preq[] VALUE="103">Sending Web Page
to other users<BR>
<INPUT TYPE=checkbox NAME=preq[] VALUE="103">Sending Web Page
to other users<BR>
<INPUT TYPE=checkbox NAME=preq[] VALUE="103">Sending Web Page
to other users<BR>

This is the code that is giving me this problem:

<?
        $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");
                        }
                }
        }
}
?>

Can anyone see the silly oversight or mistake I am making? Opinions
much appreciated!

Luis

---------------------------------------------
This message was sent using Mecha WebMail.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-db-unsubscribe <email protected>
For additional commands, e-mail: php-db-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>