How to get form_dropdown() show the selected value in Codeigniter?

南楼画角 提交于 2019-12-05 14:21:10

I think that what's probably happening is that the value in $batch may be matching what's rendering in the dropdown but not the actual key in $options for that particular option which would be the value="" portion of the html.

for example...

// this wouldn't select 'foo' as you may be thinking
$options => array('0' => 'foo', '1' => 'bar');
$batch = 'foo';
echo form_dropdown('shirts', $options, $batch);

// this would select foo
$options => array('foo' => 'foo', 'bar' => 'bar');
$batch = 'foo';
echo form_dropdown('shirts', $options, $batch);

Edit in response to OP's comment:

The batchget() method looks like it returns your $options array in the proper format and your student_get() method is returning a row_array. It appears that in the view you're assigning the value of one of the keys returned by the student_get method to be the selected value stored in $batch which is then passed in as the third argument to form_dropdown().

This all appears to be correct. As long as the value of $batch is indeed one of the array keys that is in $options then form_dropdown() will set one of the dropdown options as having been selected.

Phil Sturgeon

Debug stuff.

var_dump() $options, var_dump() $batch, look at the two and see where you went wrong.

The third option must be the value of the key, not the value of the label.

Anthony Jack is probably right.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!