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条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置