dongyilai4214 2017-03-01 10:13
浏览 47
已采纳

Codeigniter ::如何在编辑数据时基于多个数据输入添加表单

I have a table whose contents based id_product, when I edit the automatic reference is the id_product, and there are data from multiple should I pull and I give them one data of the field how to put the data from multiple database to form input type file and form input type dropdown (SELECTED).

my table color :

+--------------------------------------+
| id_color | id_product | option_color |
----------------------------------------
|    1     |     20     |    white     |
|    2     |     20     |    black     |
+--------------------------------------+

results should be like this :

<select type="select" name="color[]">
  <option value="">blue</option>
  <option value="" selected="selected">white</option>
  <option value="">black</option>
</select>

<select type="select" name="color[]">
  <option value="">blue</option>
  <option value="">white</option>
  <option value="" selected="selected">black</option>
</select>

my table image :

+--------------------------------------+
| id_image | id_product |    image     |
----------------------------------------
|    32     |     20     |  pro1.jpg   |
|    33     |     20     |  bl23.jpg   |
+--------------------------------------+

results should be like this :

<input type="file" name="additional_image[]" value="pro1.jpg">
<input type="file" name="additional_image[]" value="bl23.jpg">

</div>
  • 写回答

1条回答 默认 最新

  • duanjian3338 2017-03-01 11:50
    关注
    <?
    
    $colors = array(
        0 => 'blue',
        1 => 'white',       
        2=> 'black' 
        );
    
    
    $products = array(
        array(
            'id_color' => 1,
            'id_product' => 20,
            'option_color' => 'white',
            ),  
        array(
            'id_color' => 2,
            'id_product' => 20,
            'option_color' => 'black',
            ),
    
    );
    
    foreach ($products as $pro) { ?>
        <select type="select" name="color[]"><?
        foreach ($colors as $cid =>$color) { ?>
            <option value="" <? echo $pro['id_color']==$cid?'selected="selected"':'';?> ><? echo $color; ?></option>
        <? }
        ?></select>
    <? } ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?