-3

//模型

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);

?>

这不起作用。请帮助我从数据库中创建一个下拉列表。如果您可以编写新代码。提前致谢

4

3 回答 3

0

我不确定你是否有自动加载表单助手,如果没有,除非你在控制器中加载它,否则你不能使用 form_dropdown 函数。我没有看到您在任何地方加载表单助手。

http://codeigniter.com/user_guide/helpers/form_helper.html

于 2012-08-30T11:10:20.073 回答
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

就是这样。如果对您有用,请接受答案

于 2012-08-30T11:07:53.347 回答
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

于 2012-08-31T09:07:10.417 回答