要在同一页面中显示的复选框值
Checkbox values to be displayed in the same page
我有一个包含多行和多列的页面。
因此,当用户登录时,如果他在后台有任何条目,它应该显示在前台。显示,如果后端值为1table,如果后端值为0则不勾选
{$i=0}
{foreach from=$last7days item=date}
<tr>
<td><b> {$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}
对于 php :-
$show_details = mysql_query("select id,user,date,BREAKFAST,LUNCH,EVENING,DINNER,MIDNIGHT,timeUpdate from phpgroupware_new.foodPlan
user='$name'");
table:-
mysql> select * 来自 foodPlan;
+----+------------+------------+------------+----- -+--------+--------+--------+---------------- ---+
|编号 |用户 |日期 |早餐 |午餐 |晚上 |晚餐 |午夜|时间更新 |
+----+------------+------------+------------+----- -+--------+--------+--------+---------------- ---+
| 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 |管理员 | 2015-03-07 | 1 | 1 | 0 | 0 | 0 | 2015-03-07 12:35:57 |
| 9 |管理员 | 2015-03-08 | 1 | 1 | 0 | 0 | 0 | 2015-03-07 12:35:57 |
| 10 |管理员 | 2015-03-09 | 1 | 1 | 0 | 0 | 0 | 2015-03-07 12:35:57 |
| 11 |管理员 | 2015-03-10 | 1 | 1 | 0 | 0 | 0 | 2015-03-07 12:35:57 |
| 12 |管理员 | 2015-03-11 | 1 | 1 | 0 | 0 | 0 | 2015-03-07 12:35:57 |
| 13 |管理员 | 2015-03-12 | 1 | 1 | 0 | 0 | 0 | 2015-03-07 12:35:57 |
| 14 |管理员 | 2015-03-13 | 1 | 1 | 0 | 0 | 0 | 2015-03-07 12:35:57 |
+----+------------+------------+------------+----- -+--------+--------+--------+---------------- ---+
一组 14 行(0.00 秒)
试试这个,
<input type="checkbox" <?php
echo($breakfast == 1)? 'checked="checked"' : ''?> name="BREAKFAST[]" value="<?php echo $breakfast; ?>" >
$breakfast 是您的数据库中来自 for 循环的值。
我认为你应该删除定义不同值 0 的其他隐藏输入,只包含第一个值为 1 的输入。也许这可以帮助你开始,除非我误解了你的问题
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
}
您实际上不需要使用数组作为输入,您只需一个变量就可以了
我有一个包含多行和多列的页面。
因此,当用户登录时,如果他在后台有任何条目,它应该显示在前台。显示,如果后端值为1table,如果后端值为0则不勾选
{$i=0}
{foreach from=$last7days item=date}
<tr>
<td><b> {$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}
对于 php :-
$show_details = mysql_query("select id,user,date,BREAKFAST,LUNCH,EVENING,DINNER,MIDNIGHT,timeUpdate from phpgroupware_new.foodPlan
user='$name'");
table:-
mysql> select * 来自 foodPlan; +----+------------+------------+------------+----- -+--------+--------+--------+---------------- ---+ |编号 |用户 |日期 |早餐 |午餐 |晚上 |晚餐 |午夜|时间更新 | +----+------------+------------+------------+----- -+--------+--------+--------+---------------- ---+ | 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 |管理员 | 2015-03-07 | 1 | 1 | 0 | 0 | 0 | 2015-03-07 12:35:57 | | 9 |管理员 | 2015-03-08 | 1 | 1 | 0 | 0 | 0 | 2015-03-07 12:35:57 | | 10 |管理员 | 2015-03-09 | 1 | 1 | 0 | 0 | 0 | 2015-03-07 12:35:57 | | 11 |管理员 | 2015-03-10 | 1 | 1 | 0 | 0 | 0 | 2015-03-07 12:35:57 | | 12 |管理员 | 2015-03-11 | 1 | 1 | 0 | 0 | 0 | 2015-03-07 12:35:57 | | 13 |管理员 | 2015-03-12 | 1 | 1 | 0 | 0 | 0 | 2015-03-07 12:35:57 | | 14 |管理员 | 2015-03-13 | 1 | 1 | 0 | 0 | 0 | 2015-03-07 12:35:57 | +----+------------+------------+------------+----- -+--------+--------+--------+---------------- ---+ 一组 14 行(0.00 秒)
试试这个,
<input type="checkbox" <?php
echo($breakfast == 1)? 'checked="checked"' : ''?> name="BREAKFAST[]" value="<?php echo $breakfast; ?>" >
$breakfast 是您的数据库中来自 for 循环的值。
我认为你应该删除定义不同值 0 的其他隐藏输入,只包含第一个值为 1 的输入。也许这可以帮助你开始,除非我误解了你的问题
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
}
您实际上不需要使用数组作为输入,您只需一个变量就可以了