donglong9745 2016-05-30 23:55
浏览 31
已采纳

使用codeigniter将文本字段与行中的主键相关联

I am trying to build a bidding application. I want to a associate a textfield with the primary key of the row outputted. e.g textfield is bid_amount.

When entering the bid amount I want the bid_amount entered and the person who bid (truckerid) and the product bid on (luggage_id) to be stored in a bids table.

The outputted products to bid for are stored in another table (consignment table) Below is my model, view and controller.

View

<h2 class="page-header">
<i class="fa fa-legal"></i> &nbsp <font color="orange"> Loads To Bid For </font> 
</h2>
</div><!-- /.col -->
</div>

<?php
    foreach ($h->result() as $row) {}
?>         

      <div class="row invoice-info">
       <div class="col-sm-1 invoice-col">
        </div>
        <div class="col-sm-3 invoice-col">
        <img src="<?php echo base_url()?>/res/images/goods/1.png">              
        </div>
        <div class="col-sm-4 invoice-col">
        <address>
        Description: <?php echo $row->description;?><br>
        Location Address: <?php echo $row->l_area;?><br>
        Destination Address: <?php echo $row->d_area;?><br>
        Date: <?php echo $row->dom;?><br>
        Time: <?php echo $row->tom;?>
        </address>
        </div>
        <div class="col-sm-2 invoice-col">
        <address>
        </address>
        </div><!-- /.col -->
        <div class="col-sm-2 invoice-col">

            <?php echo form_open('truckeraccount_ctrl/bid'); ?>
            <input type="hidden" class="form-control" name="truckerid" value="<?php 
            $truckerid = $this->session->userdata('truckerid');
            echo $truckerid; ?>" required>
            <input type="text" class="form-control" name="bid_amount[$row->luggage_id]" placeholder="Bid">
            <button type="submit" class="btn bg-orange btn-flat margin">Place Bid</button>
          </div>
      </div>

Controller

public function bid() {
    $this->load->model('Truckeraccount_model');
    //  $luggage_id = $this->uri->segment(3);
    $this->Truckeraccount_model->bid();
    redirect('truckeraccount_ctrl');                    
}

Model

function bid() {  
    $data = array(
        'luggage_id' => $this->input->post('luggage_id'),
        'bid_amount' => $this->input->post('bid_amount'),
        'truckerid' => $this->input->post('truckerid')
    );
    //$this->db->where('luggage_id', $luggage_id);
    $query=$this->db->update('bids', $data);

    return $query;
  }
  • 写回答

2条回答 默认 最新

  • duanji2002 2016-05-31 04:51
    关注

    You can use the input as an associative array by changing the name. This will make the keys in the array the product ids

    try

    <input type="text" name="bidAmount[$row->productId]" />
    

    then in your PHP you can loop through the values

    foreach ($_POST['bidAmount'] as $productId => $bidAmount) {
        // do your logic here
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试