如何使用另一个表数据更新下拉列表的列表值

时间:2015-06-01 13:03:31

标签: mysql codeigniter grocery-crud

我是这个领域的新手。我正在使用CodeIgniter.Im在我的第一个系统上使用杂货crud进行crud功能。我创建了两个名为" pavings"和"类别"。在"铺路表"有一个下拉列表可以选择一个类别。当我在"类别表中添加一个类别"我希望添加的类别名称显示在铺路表的下拉列表中。

这是铺路表的编码。我只是使用数组传递下拉值,但它不是我想要的。我希望它通过类别表的数据更新(带类别列数据)请给我回答这个问题。谢谢!

 public function paving_management()
{
    $crud = new grocery_CRUD();

    $crud->set_theme('datatables');
    $crud->set_table('tbl_pavings');
    $crud->set_subject('Pavings');


    $crud->fields('type','category','color','size','qnt_per_sqft','unit_price'); //field we want to add,edit,delete
    $crud->columns ('paving_id','type','category','color','size','qnt_per_sqft','unit_price'); //fields we want to view

    //$crud->unset_columns('paving_id');    // columns we dont want to view
    $crud->display_as('type','Type')
         ->display_as('category','Category')
         ->display_as('qnt_per_sqft','Quantity per sqft')
         ->display_as('size','Size')
         ->display_as('unit_price','Unit Price')
         ->display_as('paving_id','Paving ID')
         ->display_as('color','Colour');

    $crud->unique_fields('type');   // This field must be unique

    $crud->required_fields('type','category','color','qnt_per_sqft','unit_price'); //this field are cmplsry 


    $crud->field_type('type','dropdown',
        array('cobble smooth' => 'Cobble Smoothe','uni smooth' => 'Uni Smoothe','i smooth' => 'I Smoothe','panda smooth' => 'Panda Smooth','bat smooth' => 'Bat Smooth'));  //drop down         
    $crud ->field_type('category','multiselect',
        array( "heavy duty"  => "Heavy Duty", "drive ways" => "Drive Ways"));    //multiselect      
    $crud ->field_type('color','multiselect',
        array( "red"  => "Red", "brown" => "Brown", "green" => "Green"));

1 个答案:

答案 0 :(得分:1)

检查此示例代码,以便在codeigniter中创建下拉列表。

<?php
$js = 'id="unicode" class="form-control"';
$unicode = array(
'2' => 'No',
'1' => 'Yes'
);
echo form_dropdown('unicode', $unicode, set_value('unicode'), $js);
?>

这里Dropdown id是unicode,class是form-control。

Html看起来像:

<select name="unicode" id="unicode" class="form-control">
<option value="2">No</option>
<option value="1">Yes</option>
</select>

您可以从数组中获取db中的值,然后将其存储在$unicode之类的变量中。希望这会有所帮助。查看此引用link