所以,我想一个选择自动填充下拉的“是”的选择,或者“否”。数据库查询返回的值将用于评估将选择哪个下拉列表。下拉框中选择基于数据库条目
我认为,因为它是一个真/假自动填充只写2条件,但我认为会有一个更好的(阅读:较少杂乱的代码)的方式来编写代码,将自动填充正确的选择基于数据库结果的下拉列表。
我想写将检查对所有选择的变量,则追加,将选择下拉在视图中的用户的字符串代码的基础。
我的问题是有没有一个简单的方法来做到这一点,而不是写条件语句为每一个可能的下拉值?通过要求
代码,写在PHP笨:
$this->db->select('row');
$result = $this->db->get('table');
// This just selects and returns the values. This code does work, I'm just looking for a better way to do this task that someone might know, because I'm going to have drop downs with hundreds of possibilities, of which, I want the predefined one to be selected.
// Assume $result->row = "Yes"
if ($result = "Yes") {
#Code for echo'ing radio button with "Yes" selected
}
else {
#Code for echo'ing radio button with "No" selected
}
你能详细解释一下你的问题吗?也许显示一些代码? – 2010-02-01 21:02:10
显示你的乱码,我们会告诉你如何做得更好。 – Flavius 2010-02-01 21:07:13