表单输入值在foreach循环中codeigniter

问题描述:

我有一个表单,我试图捕获它在foreach循环(循环通过数据库条目)内的输入字段值。问题是我只设法捕获在第一个输入字段输入的值。 任何人都可以帮助我在这里请。 这是我的形式:表单输入值在foreach循环中codeigniter

<form action="" method="post" role="form"> 
    <table class="table table-hover"> 
     <thead> 
      <tr> 
       <td>A/C ID</td> 
       <td>A/C NAME</td> 
      </tr> 
     </thead> 
     <tbody> 
      <?php $i = 1;?> 
      <?php foreach ($accounts as $row) { ?> 
      <tr> 
       <td><?php echo $row->acc_id; ?></td> 
       <td><?php echo $row->acc_name; ?></td> 
       <td> 
        <input name='amount<?php echo $i;?>' value="" /> 
       </td> 
      </tr> 
      <?php $i++; } ?> 
      <button type="submit">View Summary</button> 
     </tbody> 
    </table> 
</form> 

在这里我如何,我访问控制器中的值:

$i = 1; 
$values = array(
    'amount' . $i => $this->input->post('amount' . $i), 
); 

print_r($values); 
$i++; 
+0

你的控制器的循环在哪里? – andy 2014-09-21 09:14:34

+0

你能告诉我如何在控制器中编写该循环吗? – marohhher 2014-09-21 09:26:40

你可以算结果的数量,您发送给您的视图,然后循环通过你的控制器的数量

$count = number of accounts send to the view 
$i = 1; 

while ($i <= $count) { 

    $index = 'amount' . $i; 

    $values[index] = $this->input->post('amount' . $i; 
    $i++; 
} 

print_r($values); 
+0

感谢您的帮助..现在工作 – marohhher 2014-09-21 11:20:36