用于选择消息的收件箱系统复选框

发布于 2024-08-19 13:56:12 字数 177 浏览 8 评论 0原文

目前,我们正在网站中实施收件箱系统,并希望用户能够选中多条收件箱消息并单击“删除”链接来批量删除它们。

每条收件箱消息在数据库中都有其自己的 ID。

我们需要帮助的是让复选框系统正常工作。我们不知道从哪里开始;我们是否必须给每个人一个 ID 或者用 PHP 填写一些值 - 我们只是不知道。非常感谢任何帮助。

We currently are implementing an inbox system into our website and want a user to be able to checkmark multiple inbox messages and click a Delete link to mass-delete them.

Each inbox message has it's own ID in the database.

What we need help with is getting the checkbox system working. We don't know where to start with it; whether we have to give each one an ID or fill in some value with PHP - we just don't know. Any help is greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

还在原地等你 2024-08-26 13:56:13

您可以为所有复选框指定相同的名称(以 [] 结尾)和不同的值,如下所示:

<input type="checkbox" name="deletemessage[]" value="367"/>
<input type="checkbox" name="deletemessage[]" value="394"/>
<input type="checkbox" name="deletemessage[]" value="405"/>

这样,当提交表单时,PHP 会将所有选定的值放入 $_POST 内的数组中。因此,如果在上面的示例中选中顶部和底部复选框,则 $_POST['deletemessage'] 将包含 [367, 405]

You can give all your check boxes the same name, ending in [], and different values like this:

<input type="checkbox" name="deletemessage[]" value="367"/>
<input type="checkbox" name="deletemessage[]" value="394"/>
<input type="checkbox" name="deletemessage[]" value="405"/>

This way, when the form is submitted, PHP will put all the selected values into an array within $_POST. So if the top and bottom check boxes were selected in the example above, $_POST['deletemessage'] would contain [367, 405]

铜锣湾横着走 2024-08-26 13:56:13

xHTML 表单

<input type="checkbox" name="record[]" value="1" />
<input type="checkbox" name="record[]" value="2" />
<input type="checkbox" name="record[]" value="3" />
<input type="checkbox" name="record[]" value="4" />

PHP

<?php

foreach ($_POST['record'] AS $id) {

    $id = (int)$id; // Force to integer (little of security)

    // Delete the record
    mysql_query("DELETE FROM `table` WHERE `id` = {$id}");

}

?>

The xHTML form

<input type="checkbox" name="record[]" value="1" />
<input type="checkbox" name="record[]" value="2" />
<input type="checkbox" name="record[]" value="3" />
<input type="checkbox" name="record[]" value="4" />

The PHP

<?php

foreach ($_POST['record'] AS $id) {

    $id = (int)$id; // Force to integer (little of security)

    // Delete the record
    mysql_query("DELETE FROM `table` WHERE `id` = {$id}");

}

?>
月隐月明月朦胧 2024-08-26 13:56:13
<input type="checkbox" name="check[]" value=1 />
<input type="checkbox" name="check[]" value=2 />
<input type="checkbox" name="check[]" value=3 />
<input type="checkbox" name="check[]" value=4 />
<input type="checkbox" name="check[]" value=5 />

然后,这将返回一个可以循环的数组。

<?php
foreach ($_POST["check"] as $value)
{
echo "message id: $value";
}
?>

关于安全性的说明,您需要确保消息 ID 与尝试删除消息的用户相关联。

<input type="checkbox" name="check[]" value=1 />
<input type="checkbox" name="check[]" value=2 />
<input type="checkbox" name="check[]" value=3 />
<input type="checkbox" name="check[]" value=4 />
<input type="checkbox" name="check[]" value=5 />

This will then return an array you can loop through.

<?php
foreach ($_POST["check"] as $value)
{
echo "message id: $value";
}
?>

A note on security, you will want to ensure that the message id is assosciated with the user who is trying to delete the message.

说好的呢 2024-08-26 13:56:13

首先为所有复选框指定相同的名称,末尾带有方形 brqackets somename[]

,然后在提交表单(作为 POST)时 print_r($_POST)

Start by giving all the check boxes the same name with square brqackets at the end somename[]

and when you submit the form (as a POST) do print_r($_POST)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文