PHP 复选框设置为根据数据库值进行检查

PHP checkbox set to check based on database value(PHP 复选框设置为根据数据库值进行检查)
本文介绍了PHP 复选框设置为根据数据库值进行检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个系统,人们填写他们的信息,然后可以返回并编辑某些部分,基本上是输入个人信息并检查他们是否想知道额外信息,这些额外信息是复选框,其中 4 个.用户最多可以选择 4 个中的任何一个,并且数据库有 4 个字段设置为 no,如果他们选择一个,则更改为 yes.我希望他们能够返回并取消选择或重新选择这 4 个复选框中的任何一个,所以如果值为是,我希望复选框被选中,如果值不是,则取消选中.

I have a system where people fill in their information and later can go back and edit certain parts, basically the enter personal info and check whether they want to know extra info, these bits of extra infos are checkboxes, 4 of them. the user will select up to any of the 4 and the database has 4 fields set to no, if they select one it changes to yes. I want them to be able to go back and deselect or reselect any of these 4 checkboxes, so what i want s for the checkboxes to be selected if the values is yes and unselected if the value is not.

字段是 tag_1, tag_2, tag_3, tag_4

the fields are tag_1, tag_2, tag_3, tag_4

非常感谢任何帮助

我收集了某种 if 语句,但不确定如何将其包含在复选框中.

I gather some kind of if statement but not sure how to involve it in a checkbox.

<label for="tag_1">Tag 1</label>
<input type="checkbox" name="tag_1" id="tag_1" value="yes" />

伊恩

推荐答案

从数据库中提取复选框字段的信息.接下来将上面的示例行更改为:(此代码假定您已将用户信息检索到名为 dbvalue 的关联数组中,并且 DB 字段名称与 HTML 表单上的名称匹配)

Extract the information from the database for the checkbox fields. Next change the above example line to: (this code assumes that you've retrieved the information for the user into an associative array called dbvalue and the DB field names match those on the HTML form)

<input type="checkbox" name="tag_1" id="tag_1" value="yes" <?php echo ($dbvalue['tag_1']==1 ? 'checked' : '');?>>

如果您正在寻找代码来为您做所有事情,那么您来错地方了.

If you're looking for the code to do everything for you, you've come to the wrong place.

这篇关于PHP 复选框设置为根据数据库值进行检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)