Hi to all. I am a newbie to PHP programming. In my project I'm having a student registration form. In that page I've populated checkboxes from database values for students who wants to enroll more than one classes. Everything got done. Now I need to give edit option to student in case they want to change the class selection. I tried the below code for show checked classes. It shows the perfect answer (I mean my table have 5 classes for example when the time of registration student selected 2 checkboxes my below code shows the exactly what they've selected) But what I want is I need to show previously selected classes as checked as well as rest as unchecked.

<?php $stu_id = $rows["id"];?>                       
                    <?php                        
                        $data =  mysql_query("select a.id as id ,a.class_name as class_name from class a,stud_class b where b.class_id = a.id and b.stud_id = '$stu_id'") or die(mysql_error());
                        while ($val = mysql_fetch_array($data))
                        {  ?>
                    <input type="checkbox" name="class[]" id="class" value="<?php print $val['id']; ?>"> 
                    <?php print isset($val['class_name'])?$val['class_name']:"";  ?>  <br>

            <?php    } 

            ?>

Please anyone help me with this. Thanks in advance

Hi Guys, I solved it by myself, We have to separate the process like the code below. This coding working like charm.

<?php                    

                        $data1 =  mysql_query("select * from class where id not in (select class_id from stud_class where stud_id = '$stu_id')") or die(mysql_error());
                        while ($val1 = mysql_fetch_array($data1)){?>
                        <input type="checkbox" name="class[]" id="class" value="<?php print $val1['id']; ?>"> 
                        <?php print isset($val1['class_name'])?$val1['class_name']:""; } ?>  <br/>    

                        <?php $data =  mysql_query("select a.id as id ,a.class_name as class_name from class a,stud_class b where b.class_id = a.id and b.stud_id = '$stu_id'") or die(mysql_error());
                        while ($val = mysql_fetch_array($data))                         
                        {  ?>
                    <input type="checkbox" name="class[]" id="class" checked = "checked" value="<?php print $val['id']; ?>"> 
                    <?php print isset($val['class_name'])?$val['class_name']:"";  ?>  <br/>
                    <?php    } ?>

Anyway thanks for you all!!!!!!!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.