duanpao4172 2016-05-05 04:29
浏览 32
已采纳

使用PHP,HTML和MySQli动态创建复选框列表[复制]

This question already has an answer here:

I'm trying to dynamically create a checkbox list using employees from my database. The list is for the purpose of taking attendance at meetings. I tried using a solution I found on this site to create the list but I'm getting an error that there is an unexpected end in my code. I can't find it.

<?php
   $servername = "localhost";
   $username = "root";
   $password = "password";
   $dbname = "purpletrainer";

   // Create connection
   $conn = new mysqli($servername, $username, $password);

   // Check connection
   if ($conn->connect_error) {
       die("Connection failed: " . $conn->connect_error);
   } 
   //echo "Connected successfully";

   $MeetingID = $_POST["meetingid"];

   $sql = "SELECT employee.emplname
           FROM purpletrainer.employee, purpletrainer.meeting
           WHERE employee.empmngrid=meeting.meetingleader
           AND meetingid='$MeetingID'";

       $result = $conn->query($sql);

       //Iterate over the results that you've gotten from the database
       if ($result->num_rows > 0){
               while($employee = $result->fetch_assoc())
               {
               ?>
                       <div>
                               <form action="processlist.php" method="post">
                               <span><?php echo $employee['emplname']; ?></span>
                               <input type="checkbox" name="employees[]" value= '<?php echo $employee[0]; ?>' /><br />
                               </form>
                       </div>
               }

           }
</div>
  • 写回答

3条回答 默认 最新

  • duanrong5927 2016-05-05 04:37
    关注

    Actually have not complete your while loop and if bracket syntax error. Your if condition code replace with below code.

    if ($result->num_rows > 0){
                   while($employee = $result->fetch_assoc())
                   {
                   ?>
                           <div>
                                   <form action="processlist.php" method="post">
                                   <span><?php echo $employee['emplname']; ?></span>
                                   <input type="checkbox" name="employees[]" value= '<?php echo $employee[0]; ?>' /><br />
                                   </form>
                           </div>
                <?php
                   }
    
               }
               ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像