[eluser]petroz[/eluser]
Hi Guys,
I am a lil new to codeigniter, but so far I love it.
I am getting hung up on dynamic form_dropdowns. I did some searching but I cant seem to find the answer I am looking for... There is a option label showing up which I dont want... also, I am unable to define the selected option.
Any help would be greatly appreciated. I have attached my code and results.
First, my model. I query the database for the option value (bid) then the option (brand_name). I am guess my problem lies here...
Code:
//this one gets all the possible options
function get_brand_bid(){
$this->db->select('bid, brand_name');
$this->db->where('status = 0');
$query = $this->db->get('brands');
if ($query->num_rows() > 0){
foreach ($query->result_array() as $row){
$data[] = array(
$row['bid'] => $row['brand_name']
);
}
}
$query->free_result();
return $data;
}
//this is supposed to get the selected option
function get_brand($sid){
$this->db->select('`brands`.`bid`, `brands`.`brand_name`');
$this->db->where('`styles`.`sid`', $sid);
$this->db->where('`styles`.`bid` = `brands`.`bid`');
$query = $this->db->get('`styles`, `brands`');
if ($query->num_rows() > 0){
foreach ($query->result_array() as $row){
$data = array(
$row['bid'] => $row['brand_name']
);
}
}
$query->free_result();
return $data;
}
}
My controller (simplified)
Code:
//get all brands
$data['brands'] = $this->brands_model->get_brand_bid();
//get selected brand
$data['brand'] = $this->brands_model->get_brand($sid);
//load the view
$data['main_content'] = 'inventory/list_inventory';
$this->load->view('includes/template', $data);
My View (simplified)
Code:
echo form_label('Brand');
echo form_dropdown('brand',$brands, $brand);
I have attached an image showing what the drop down looks like as well.