douxian9706 2014-09-09 05:19
浏览 55
已采纳

Codeigniter:在动态文本框/ textarea上生成id

I have a problem generating ID's on my dynamic textareas.

Here is my model:

public function select_fields3($tablename3){
     $this->load->library('table');
     $fields = $this->db->field_data($tablename3['table1']);
     return $fields;
 }

Here is my controller:

 public function add_all_inventory(){
    $this->data['title'] = "Add New Inventory";
    $this->load->vars($this->data);
    $table_naming_1 = $_POST['table1'];
    $this->load->view('homeview');

    $select_inv['inventorytype'] = $this->inventory_model->select_tables();
    $this->load->view('inventoryview', $select_inv);

    $select_fields['add_all'] = $this->inventory_model->select_fields3($this->input->post());

    $values_array1 = array('add_all_1' => $select_fields['add_all'],
                           'tablename1' => $table_naming_1);

    $this->load->view('add_all_inventory', $values_array1);

    $this->load->view('footer_view');
}

No need to focus on $select_inv, it's just a reference so I can get the fields of the table loaded. And here is my view:

<div class="row">
<fieldset>
    <form action="" method="POST" id="frm_add_all_inventory" name="frm_add_all_inventory">
    <legend>Add New <input style="border: none; background-color: transparent;" type="text" name="txt_table" id="txt_table" value="<?php echo $tablename1; ?>" readonly/></legend>
            <table style="">
                <?php foreach($add_all_1 as $row) { ?>
                <tr style="">
                    <td style=" height: 50px; width: 100px;font-size: 10pt;"><input style="border: none; background-color: transparent; width: 100%;" type="text" value="<?php echo $row->name; ?>:" readonly/></td>
                    <td style=" height: 50px; width: 200px;"><textarea style="resize: none; font-size: 10pt; width: 100%;"></textarea></td>
                </tr>
                <?php } ?>
                <tr>
                    <td></td>
                    <td></td>
                    <td>
                        <button type="button" class="btn_add_all_inventory btn-success btn-sm"><span class="glyphicon glyphicon-ok"></span>&nbsp;Save</button>
                        <button type="button" class="btn_cancel_all_inventory btn-danger btn-sm"><span class="glyphicon glyphicon-remove"></span>&nbsp;Cancel</button>
                        <button type="button" class="btn_clear_all_inventory btn-warning btn-sm" onclick="document.getElementById('frm_add_all_inventory').reset();"><span class="glyphicon glyphicon-refresh"></span>&nbsp;Clear</button>
                    </td>
                </tr>
             </table>
        </form>
</fieldset>

You see my textarea tag is inside the foreach loop, I wonder how can I generate an ID on my textarea on this one. Hope you could help me. Thank you in advance!

  • 写回答

1条回答 默认 最新

  • duangekui7451 2014-09-09 05:44
    关注

    Can you try it?

    Is this you are trying for?

    <?php
        $count=0; /* Initialize variable */
        foreach($add_all_1 as $row) {
    ?>
          <tr style="">
           <td style=" height: 50px; width: 100px;font-size: 10pt;"><input style="border: none; background-color: transparent; width: 100%;" type="text" value="<?php echo $row->name; ?>:" readonly/></td>
            <td style=" height: 50px; width: 200px;"><textarea style="resize: none; font-size: 10pt; width: 100%;"></textarea></td>
           </tr>
    <?php 
         echo 'Generated Id: ID'.$count; /*Something Prefix*/
         $count=$count+1; /*Increase the Variable*/
        } 
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题