2012-08-30 38 views
-3

下拉列表//模型codigniter從數據庫

function shop_dropdown() 
{ 
    $this->db->select('shop'); 
    $this->db->from('shop'); 
    //$this->db->where('category_online', 1); 
    $query = $this->db->get(); 
    foreach($query->result_array() as $row) 
    { 
     $data[$row['id']]=$row['name']; 
    } 
    return $data; 

} 

控制器//

function shop_dropdown() 
{ 
    $data = array(); 

    $this->load->model('shop_model'); 
    $shop['select_options'] =    $this->shop_model->shop_dropdown(); 
    $this->load->view('shop/product_view', $shop); 


} 

視圖//

<?php 
    echo form_dropdown('shop', $select_options); 

?> 

這不是不working.please幫我創建從數據庫中下載下來。如果你可以寫一個新的代碼。 由於事先

+0

恐怕你要學習,如果你希望任何幫助,如何正確地提出問題。告訴「它不起作用」意味着什麼都沒有,並且對你的要求的常見答案是「如此修正」。 –

+0

我是新來here.please修復這個問題。我搜索了很多次,但我沒有得到準確的代碼。 –

+0

閱讀關於如何正確提問的常見問題解答:http://stackoverflow.com/faq#howtoask –

回答

0

修改這樣

function shop_dropdown() 
{ 
    $data = array(); 
    $this->load->model('shop_model'); 
    $shop = $this->shop_model->shop_dropdown(); 
    $this->load->view('shop/product_view', $shop); 
} 

,並在您的視圖

echo form_dropdown('shop', $shop->option);//option is an value taking form database 

這it.accept答案是否對你有用

0

你選擇模型中的 '店' 列。 我覺得你的模型應該是這樣的

function shop_dropdown() 
{ 
$this->db->select('id,name'); //column names you want to select, can be optional if you want to select all columns. 
$this->db->from('shop'); //table name, required 
//$this->db->where('category_online', 1); 
$query = $this->db->get(); 
foreach($query->result_array() as $row) 
{ 
$data[$row['id']]=$row['name']; //make sure 'id' and 'name' ,columns are present in table 
} 
return $data; 

} 

我希望你已經編輯的application/config/databse.php