如何检查数据库并因此检查单选按钮? [英] How to check database and, as a result, check a radio button?

查看:58
本文介绍了如何检查数据库并因此检查单选按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将这些个人资料保存在数据库中,其中包含许多随机信息,例如姓名,性别,年龄等.

I have these profiles saved in a database with lots of random information like name, gender, age, etc.

用户可以通过单击超链接来编辑其个人资料,并将其带到一种类似于他们首次注册时填写的表格的形式.我已经对其进行了设计,因此所有文本输入字段都已经具有它们以前填写的值.这是一个看起来像这样的示例:

The user can edit their profile by clicking a hyperlink and it takes them to a form much like the one they filled out when they first registered. I've designed it so all the text input fields already have the values they had previously filled in. Here's an example of what one looks like:

<input type="text" name="fname" value="<?php echo $result['firstName']; ?>"/>

如您所见,我正在从查询数据库创建的数组中回显它们的名称.但是问题是我在某些输入(例如性别)中使用了单选按钮(也有下拉框).

As you can see I'm echoing their name from the array I created from querying the database. But the problem is I used radio buttons (and drop down boxes too) for some of these inputs like gender.

因此,一旦从数据库中确定它们是男性还是女性,如何检查相应的单选按钮?

So how do I check the appropriate radio button once I establish they're male or female from the database?

推荐答案

<input type="radio" name="gender" value="m" <? if($row['gender'] == "m") print "selected";?> >
<input type="radio" name="gender" value="f" <? if($row['gender'] == "f") print "selected";?> >

我认为这很简单.因为它们不能同时是两者.

i think it's simplier. because they can;t be both, at the same time.

这篇关于如何检查数据库并因此检查单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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