在php中显示3列中的复选框动态表

时间:2016-04-01 16:28:40

标签: php mysql

我有一个主题数据库表。我有一个网页,显示3列中的主题列表,以便用户可以使用复选框选择主题。我遇到的挑战是列表显示需要很长时间。代码如下:

<?php
   $subjects = mysql_query("select id, name from subjects WHERE exam_type_id='0' OR exam_type_id='$exam_type_id' ORDER BY name");
   $noOfSubjects = mysql_num_rows($subjects);
   ?>
<form name="form1" method="post" action="" class="FormCss" onsubmit=" return window.confirm('You are about to submit selected subjects. If you are not sure, cancel');">
   <table>
      <tr class="FormLabel2">
         <td align="left" colspan="3" valign="top"></td>
      </tr>
      <?php
         $i = 1;
         while ($subject = mysql_fetch_array($subjects)){


             // if it is a value that is supposed to be in the 1st cell of a row, print tr
             if ($i==1 || $i==4 || $i==7 || $i== 10){
                 ?>
      <tr>
         <?php
            }

            // print a td if value is not suppose to be the last on a row
            if ($i%3 !=0){

                ?>
         <td><input type="checkbox" name="subject[]"
            value="<?php echo $subject['id']?>" <?php if (isCompulsoryMockSubject($subject['id'])){?> onclick="return false;" onkeydown="return false;" <?php }else{}?> <?php if (isCompulsoryMockSubject($subject['id'])){?> CHECKED="checked" <?php }else{}?> <?php if (hasSelectedSubject($_SESSION['candidate_id'], $exam_type_id, $subject['id'])){?> checked="checked" <?php }?>><?php echo $subject['name'];?>
         </td>
         <?php
            }else{
                // end the row
                ?>
         <td><input type="checkbox" name="subject[]"
            value="<?php echo $subject['id']?>"  <?php if (isCompulsoryMockSubject($subject['id'])){?> onclick="return false;" onkeydown="return false;" <?php }?> <?php if (isCompulsoryMockSubject($subject['id'])){?> CHECKED="checked" <?php }else{}?> <?php if (hasSelectedSubject($_SESSION['candidate_id'], $exam_type_id, $subject['id'])){?> checked="checked" <?php }?>><?php echo $subject['name'];?>
         </td>
      </tr>
      <?php
         }
         $i++;
         }
         ?>
      <tr>
         <td width="34%" align="left" valign="top" class="FormLabel2">&nbsp;</td>
         <td width="33%" align="left" valign="top"><span
            class="FormLabel2"> <input name="Submit" type="submit"
            class="loginInputSubmit" value="Save"> </span></td>
         <td width="33%" align="left" valign="top">&nbsp;</td>
      </tr>
      <tr>
         <td align="left" valign="top" class="FormLabel2">&nbsp;</td>
         <td colspan="2" align="right" valign="top" class="FormLabel2">&nbsp;</td>
      </tr>
   </table>
</form>

0 个答案:

没有答案