doukoumi3389 2015-03-07 08:53
浏览 66
已采纳

复选框值将显示在同一页面中

I have a page with multiple rows and columns.

enter image description here

So, when a user is logged in, if he has any entry in the back end, it should be displayed in front end. Display, if value is 1 in backend table, and should be unchecked if 0 is in back end.

                        {$i=0}
                        {foreach from=$last7days item=date}
                        <tr>

                             <td><b>&nbsp;&nbsp;{$date}</b><input type='hidden' name='date[]' value ='{$date}'></td>
                             <td><input type='checkbox' name='BREAKFAST[]' value='1' ><input type='hidden' name='BREAKFAST[]' value='0'></td>
                              <td><input type='checkbox' name= 'LUNCH[]' value='1'><input type='hidden' name= 'LUNCH[]' value='0'></td>
                             <td><input type='checkbox' name= 'EVENING[]' value='1'><input type='hidden' name= 'EVENING[]' value='0'></td>
                             <td><input type='checkbox' name= 'DINNER[]' value='1'><input type='hidden' name= 'DINNER[]' value='0'></td>
                              <td><input type='checkbox' name= 'MIDNIGHT[]' value='1'><input type='hidden' name= 'MIDNIGHT[]' value='0'></td>
                        </tr>
                        {/foreach}

for the php :-

   $show_details =   mysql_query("select id,user,date,BREAKFAST,LUNCH,EVENING,DINNER,MIDNIGHT,timeUpdate from phpgroupware_new.foodPlan
                        user='$name'");

table:-

mysql> select * from foodPlan;
+----+------------+------------+-----------+-------+---------+--------+----------+---------------------+
| id | user       | date       | BREAKFAST | LUNCH | EVENING | DINNER | MIDNIGHT | timeUpdate          |
+----+------------+------------+-----------+-------+---------+--------+----------+---------------------+
|  1 | monisha.md | 2015-03-07 |         1 |     1 |       1 |      1 |        1 | 2015-03-07 11:43:45 |
|  2 | monisha.md | 2015-03-08 |         0 |     0 |       0 |      0 |        0 | 2015-03-07 11:43:45 |
|  3 | monisha.md | 2015-03-09 |         0 |     0 |       0 |      0 |        0 | 2015-03-07 11:43:45 |
|  4 | monisha.md | 2015-03-10 |         0 |     0 |       0 |      0 |        0 | 2015-03-07 11:43:45 |
|  5 | monisha.md | 2015-03-11 |         0 |     0 |       0 |      0 |        0 | 2015-03-07 11:43:45 |
|  6 | monisha.md | 2015-03-12 |         0 |     0 |       0 |      0 |        0 | 2015-03-07 11:43:45 |
|  7 | monisha.md | 2015-03-13 |         0 |     0 |       0 |      0 |        0 | 2015-03-07 11:43:45 |
|  8 | admin      | 2015-03-07 |         1 |     1 |       0 |      0 |        0 | 2015-03-07 12:35:57 |
|  9 | admin      | 2015-03-08 |         1 |     1 |       0 |      0 |        0 | 2015-03-07 12:35:57 |
| 10 | admin      | 2015-03-09 |         1 |     1 |       0 |      0 |        0 | 2015-03-07 12:35:57 |
| 11 | admin      | 2015-03-10 |         1 |     1 |       0 |      0 |        0 | 2015-03-07 12:35:57 |
| 12 | admin      | 2015-03-11 |         1 |     1 |       0 |      0 |        0 | 2015-03-07 12:35:57 |
| 13 | admin      | 2015-03-12 |         1 |     1 |       0 |      0 |        0 | 2015-03-07 12:35:57 |
| 14 | admin      | 2015-03-13 |         1 |     1 |       0 |      0 |        0 | 2015-03-07 12:35:57 |
+----+------------+------------+-----------+-------+---------+--------+----------+---------------------+
14 rows in set (0.00 sec)

  • 写回答

2条回答 默认 最新

  • douzhan1963 2015-03-07 09:15
    关注

    I think you should remove the other hidden input that defines a different value 0 and just include the first input with value 1. maybe this can help you start unless i misunderstood your question

    if (isset($_POST['BREAKFAST'])
    {
    $breakfast = $_POST['BREAKFAST'];
    
    foreach($breakfast as $item) 
    if($item == 1) //that means box is checked
    // what do you want to do
    else
    // what you want to do if box is not checked
    }
    

    you actually don't need to use an array for your input you will be fine with just a variable

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

报告相同问题?

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证