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>
    <? } ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看