【问题标题】:How to update list values of a drop down list with a another table data如何使用另一个表数据更新下拉列表的列表值
【发布时间】:2015-06-01 13:03:30
【问题描述】:

我是这个领域的新手。我正在使用 CodeIgniter 开发我的第一个系统。我使用杂货店的 crud 作为 crud 功能。我创建了两个名为“pavings”和“category”的表。在“paving表”有一个下拉列表来选择一个类别。当我将一个类别添加到“类别表”时,我希望添加的类别名称显示在铺路表的下拉列表中。

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

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

【问题讨论】:

    标签: mysql codeigniter grocery-crud


    【解决方案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

    【讨论】:

    • 感谢您的解决方案,我会尽力理解并应用它。非常感谢! :)
    猜你喜欢
    • 2021-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-13
    • 1970-01-01
    • 2012-10-20
    • 1970-01-01
    • 2015-08-20
    相关资源
    最近更新 更多