[英]Pass the string value of drop down using codeigniter
I am new to codeigniter and I made a web application that have three dropdown list in it. 我是Codeigniter的新手,我制作了一个Web应用程序,其中包含三个下拉列表。 My problem is that when I am now saving to database the id was saved instead of the value in the drop down list.
我的问题是,当我现在保存到数据库时,已保存ID,而不是下拉列表中的值。 Here is my model code for the drop downs:
这是下拉菜单的模型代码:
function get_store()
{
$this->db->select('ID');
$this->db->select('StoreName');
$this->db->from('store');
$query = $this->db->get();
$result = $query->result();
// array to store id and storename
$id = array('-SELECT-');
$storename = array('-SELECT-');
for($i = 0;$i < count($result);$i++)
{
array_push($id,$result[$i]->ID);
array_push($storename,$result[$i]->StoreName);
}
return $store_result = array_combine($id,$storename);
}
function get_supplier()
{
$this->db->select('ID');
$this->db->select('SupplierName');
$this->db->from('supplier');
$query = $this->db->get();
$result = $query->result();
// array to store id and storename
$id = array('-SELECT-');
$suppliername = array('-SELECT-');
for($i = 0;$i < count($result);$i++)
{
array_push($id,$result[$i]->ID);
array_push($suppliername,$result[$i]->SupplierName);
}
return $supplier_result = array_combine($id,$suppliername);
}
function get_operation()
{
$this->db->select('ID');
$this->db->select('OperationName');
$this->db->from('operation');
$query = $this->db->get();
$result = $query->result();
// array to store id and storename
$id = array('-SELECT-');
$operationname = array('-SELECT-');
for($i = 0;$i < count($result);$i++)
{
array_push($id,$result[$i]->ID);
array_push($operationname,$result[$i]->OperationName);
}
return $operation_result = array_combine($id,$operationname);
}
and this is the code in my controller that I use: 这是我使用的控制器中的代码:
$data['store'] = $this->wip_model->get_store();
$data['suppliersname'] = $this->wip_model->get_supplier();
$data['operation'] = $this->wip_model->get_operation();
and this is how I used it in my view: 这就是我认为的用法:
<?php $attributes = 'class="form-control" id="store"';
echo form_dropdown('store',$store,set_value('store',$store),$attributes);?>
Kindly help me because I am stuck... 请帮助我,因为我被困住了...
is this what you need? 这是您需要的吗?
<div class="form-group">
<label>Store Name</label>
<?php $attributes = 'class="form-control" id="store"';
echo form_dropdown('store',$store,set_value('store',$store),$attributes);?>
<span class="text-danger"><?php echo form_error('store');?></span>
</div>
see this 看到这个
<select name="agama" id="agama">
<option value="1">store 1</option>
<option value="2">store 2</option>
</select>
in this code,when we posting the values to controller,we get values 1 or 2. The same situation in your problem. 在此代码中,当我们将值发布到控制器时,我们将获得值1或2。与您的问题相同的情况。 you can do it in 2 ways.
您可以通过2种方式来实现。 one is that.
一是。 when you get the id,you can write a model query to find the name of that id.
当获得ID时,您可以编写模型查询以查找该ID的名称。 otherwise you can set option value as value in the drop down list
否则,您可以将选项值设置为下拉列表中的值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.