duanguanye4124 2012-04-10 17:34
浏览 19
已采纳

多行和列复选框php

currently i have produced a set of checkbox based from database

It looks like

               Week 1        Week 2       Week 3       Week 4  .....
Student 1        []           []           []            []
Student 2        []            []          []            []
Student 3        []            []          []            [] 
Student 4        []            []          []            []
.....

[] represents checkbox

How do i get whatever ticked by user? I am using attendance_list[] as name for checkbox but however when one is ticked, it returns value for all users.

Thank you.

  • 写回答

2条回答 默认 最新

  • doufuhao8085 2012-04-10 17:46
    关注

    You should use a multi-dimensional array to represent students and their attendance.

    For example,

    <!-- Student 1, Week 1 to 4 -->
    <input type='checkbox' name='attendance_list[1][1]' />
    <input type='checkbox' name='attendance_list[1][2]' />
    <input type='checkbox' name='attendance_list[1][3]' />
    <input type='checkbox' name='attendance_list[1][4]' />
    
    
    <!-- Student 2, Week 1 to 4 -->
    <input type='checkbox' name='attendance_list[2][1]' />
    <input type='checkbox' name='attendance_list[2][2]' />
    <input type='checkbox' name='attendance_list[2][3]' />
    <input type='checkbox' name='attendance_list[2][4]' />
    
    <!-- And, so on.. -->
    

    Server side, you'll get an array of elements that have been checked. Using the indexes of the array, you can determine which student was in attendance during which weeks.

    If all of the above checkboxes were checked, your array would look like so:

    Array
    (
        [attendance_list] => Array
            (
                [1] => Array
                    (
                        [1] => on
                        [2] => on
                        [3] => on
                        [4] => on
                    )
    
                [2] => Array
                    (
                        [1] => on
                        [2] => on
                        [3] => on
                        [4] => on
                    )
    
            )
    
    )
    

    This indicates that Student 1 and Student 2 were in attendance for all 4 weeks.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度