使用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;
  }

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
}

You can use hidden text box to get bid.

<?php
foreach ($products->result() as $row)  
{ ?>  
<?php echo $row->price;?>       
<input type="hidden" name="bid[]" value="<?php echo $row->bid;?>">
<input type="text" name="bidAmount[]" placeholder="place bid amount">
<?php }  ?>

Now bid and bidAmount both will have same counts of array. So that use for loop to get bid value and bidAmount value.

for ($i=0; $i < count($_POST['bid']); $i++) { 
    $bid = $_POST['bid'][$i]; \\ You can get bid value here
    $bidAmount = $_POST['bidAmount'][$i]; \\ You can get bid amount value here
}

Hope this answer will be helpful. If it is correct then don't forget to mark as correct answer. Cheers.