Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Forms Codeigniter PHP获取选项值_Forms_Codeigniter - Fatal编程技术网

Forms Codeigniter PHP获取选项值

Forms Codeigniter PHP获取选项值,forms,codeigniter,Forms,Codeigniter,我有一个复杂的人口重新分配系统,可以工作,但它很麻烦 我有一个出生国的下拉菜单,当用户提交表单时,它会被扔进数据库。如果数据库中有什么内容,则下拉菜单将重新填充数据库中的任何内容 我从数据库中获得如下值: $birthplacecountry = (!set_select('birthplacecountry') && $birth_citizenship) ? $birth_citizenship[0]['birthplacecountry'] : (set_select('b

我有一个复杂的人口重新分配系统,可以工作,但它很麻烦

我有一个出生国的下拉菜单,当用户提交表单时,它会被扔进数据库。如果数据库中有什么内容,则下拉菜单将重新填充数据库中的任何内容

我从数据库中获得如下值:

$birthplacecountry = (!set_select('birthplacecountry') && $birth_citizenship) ? $birth_citizenship[0]['birthplacecountry'] : (set_select('birthplacecountry') ? set_select('birthplacecountry') : '');
<option value="Afganistan" <?php if ($birthplacecountry == 'Afganistan') echo 'selected="selected"';?>>Afghanistan</option>
<option value="Albania" <?php if ($birthplacecountry == 'Albania') echo 'selected="selected"';?>>Albania</option>
<option value="Algeria" <?php if ($birthplacecountry == 'Algeria') echo 'selected="selected"';?>>Algeria</option>
<option value="American Samoa" <?php if ($birthplacecountry == 'American Samoa') echo 'selected="selected"';?>>American Samoa</option>
这很好,因为我的选择如下所示:

$birthplacecountry = (!set_select('birthplacecountry') && $birth_citizenship) ? $birth_citizenship[0]['birthplacecountry'] : (set_select('birthplacecountry') ? set_select('birthplacecountry') : '');
<option value="Afganistan" <?php if ($birthplacecountry == 'Afganistan') echo 'selected="selected"';?>>Afghanistan</option>
<option value="Albania" <?php if ($birthplacecountry == 'Albania') echo 'selected="selected"';?>>Albania</option>
<option value="Algeria" <?php if ($birthplacecountry == 'Algeria') echo 'selected="selected"';?>>Algeria</option>
<option value="American Samoa" <?php if ($birthplacecountry == 'American Samoa') echo 'selected="selected"';?>>American Samoa</option>
>阿尔巴尼亚
>美属萨摩亚
但是,手动将$birthcplacecountry与值的名称进行比较是很烦人的。有没有一种比较期权价值的一般方法


在codeIgniter中,某些功能的工作原理如下:如果($birthcplacecountry==this.option.value)

,则应使用它生成一个选择/下拉列表,即

$options = array(
    'Afganistan'  => 'Afganistan',
    'Albania'    => 'Albania',
);
echo form_dropdown('birthplacecountry', $options, 'Albania');
在此示例中,将创建一个名为
出生地国家的
下拉列表
,并选择
选项
阿尔巴尼亚
,第二个。第三个参数设置所选的
选项
,因此,当您想用所选选项重新填充表单时,可以执行如下操作

echo form_dropdown('birthplacecountry', $options, set_select('birthplacecountry', $this->input->post('birthplacecountry') );

哇,已经有一个相同的问题了!