获取PHP中未选中和选中的复选框的值 [英] Get values of an unchecked and checked checkboxes in PHP

查看:147
本文介绍了获取PHP中未选中和选中的复选框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

概述:

这是html页面上的样子。

Here's what it looks like on html page.

>

因此每一行的复选框都有不同的名称,例如 name =doctor_0 [],每行增加一行。因此,下一行将是 name =doctor_1 [],其相应的默认值为 0

So each row of checkboxes has it's different names, for example name="doctor_0[]", it increments every row. So the next row would be name="doctor_1[]" their corresponding default value would be 0

因此,在亲眼的代码视图中,它将是

So in eye friendly code view it would be

// First row
<td><input type="checkbox" name="doctor_0[]" class="day_cbox" value="0"></td>
<td><input type="checkbox" name="doctor_0[]" class="day_cbox" value="0"></td>

// Second row
<td><input type="checkbox" name="doctor_1[]" class="day_cbox" value="0"></td>
<td><input type="checkbox" name="doctor_1[]" class="day_cbox" value="0"></td>

等等...

现在进入问题

我的问题是当复选框未选中时,数据不会传递到 $ _ POST

My problem is when the checkbox aren't checked, the data isn't passed into $_POST.

我知道通常它不工作,所以不太好的选择是创建输入字段 hidden 所以它会得到的值,当复选框不检查。但问题是,这是一个数组。

I know that normally it doesn't work that way, so the not-so-good alternative is to create input field of hidden so it would get the value when the checkbox aren't check. But the problem is, this one's an array.

我尝试过几个解决方案,在我的问题类似于的问题,但它不工作, 。这不是意味着动态或使用数组。

I've tried several solutions that was told in my questions that are similar to this below, but it doesn't work that way though. Well it's not meant to be dynamic or using arrays. Correct me if I'm wrong, my bad about that.

那么,这些东西有什么解决方案吗?

So, are there any solutions for this stuff?

一个帮助或建议或建议会是好的。

A help or suggestion or advice would be good.

感谢。

this。

获取未选中复选框的值

帖子未选中的复选框

如何在表单发布时在checkbox元素中取消选中复选框的值?

如何从复选框获取未选中的值?

http://www.webmasterworld.com/php/ 4449836.htm

推荐答案

感谢在我的问题的评论部分帮助我的人。

Thanks to people who helped me in the comment section of my question.

这是我的代码的最终版本。

Here's my final version of my code.

所以我做通常的 while循环使用 mysql 检索数据。

So I'm doing the usual while loop to retrieve data using mysql. Well don't get mad at me I was assigned to years old of web application for certain company.

不管怎样,我用@ Bad_boy的逻辑来解决这个问题。

Anyhow, I used @Bad_boy's logic to solve this issue.

我的旧代码是

注意: $ ctr 是每行的增量值。

echo '
    <td>
        <input type="checkbox" name="doctor_'. $ctr .'[]" class="day_cbox" value="1">
    </td>
';

和tada!我不善于解释它是如何工作,但是,它的工作!哈哈哈!谢谢!

And tada! I'm not good at explaning how it works but yeah, it worked! Hahahaha! Thanks!

while ($result = mysql_fetch_array($row)) {

    echo '
        <tr class="row-doctor">
            <td align="center">'. ucwords(strtolower($result['doctor_name'])) .'</td>
        ';

            for ($i = 1; $i <= 25; $i++) {

                echo '
                    <td>
                        <input type="hidden" name="doctor_'. $ctr .'['. $i .']" value="0">
                        <input type="checkbox" name="doctor_'. $ctr .'['. $i .']" class="day_cbox" value="1">
                    </td>
                ';
            }

    echo '
            <td align="center" class="blue strong"><span class="frequency_'. $ctr .'">0</span></td>
        </tr>
    ';

    $ctr++;
}

这篇关于获取PHP中未选中和选中的复选框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆