Codeigniter使用单选按钮多次插入

时间:2014-07-29 02:12:18

标签: php mysql codeigniter

HI  I NEED YOUR HELP.. 

I have this VIEW which show all items according to its company 

   <?php foreach($item_list as $item2):?>
    <tr>
     <input type = "hidden" name = "status[]" value ="5" >
     <td><input type = "text" name = "item_id[]" value ="<?php echo $item2->item_id ?>" ></td>
     <td><?php echo $item2->item_desc?></td>
     <td><?php echo $item2->serial_num ?></td>
     <td><input type = "checkbox" name = "JobStatus[]" value = "quotation" ></td>
     <td><input type = "checkbox" name = "JobStatus[]" value = "job order" ></td>                                    
     </tr>
    <?php endforeach; ?>

---------------------------------------- html输出----- ----------------------------------

                             <tr>
     <input type = "hidden" name = "status[]" value ="5" >
   <td><input type = "text" name = "item_id[]" value ="146" ></td>
   <td>sample item 01</td>
   <td>123</td>
   <td><input type = "radio" name = "JobStatus[]" value = "quotation" ></td>
   <td><input type = "radio" name = "JobStatus[]" value = "job order" ></td>                                     
 </tr>
                                 <tr>
     <input type = "hidden" name = "status[]" value ="5" >
   <td><input type = "text" name = "item_id[]" value ="147" ></td>
   <td>sample item 02</td>
   <td>21344</td>
   <td><input type = "radio" name = "JobStatus[]" value = "quotation" ></td>
   <td><input type = "radio" name = "JobStatus[]" value = "job order" ></td>                                     
 </tr>

我的问题是我想将这个值插入新值(status,item_id,item_desc,serial_num,JobStatus)到mysql中的引用表。如果在单元格item_id 146行上单击I,它将同样插入item_id 146下的所有值到item_id 147它将在147 item_id下插入所有项目值

2 个答案:

答案 0 :(得分:0)

所以你想根据它的工作状态来检查单选按钮?????

如果是这样,请尝试这些方法(我不知道您的数据库是如何设置的,因此您必须更改以下内容):

<?php foreach($query as $item):?>

<td><input type = "text" name = "item_id" value ="<?php echo $item->item_id ?>" ></td>
<td><?php echo $item->item_desc?></td>
<td><?php echo $item->serial_num ?></td>
<td><input type="radio" name="JobStatus" value="quotation" <?php $item->job_status == 'quotation' ? echo "checked" : null; ?> ></td>
<td><input type="radio" name="JobStatus" value="job order" <?php $item->job_status == 'job order' ? echo "checked" : null; ?> ></td>
</tr>

<?php endforeach; ?>

答案 1 :(得分:0)

将整个循环用form

括在action="index.php/controller/method"标记内

在你的控制器中,

public function method() {
    $items = $this->input->post('item_id', TRUE);
    $job_status = $this->input->post('JobStatus', TRUE);
    $stati = $this->input->post('status', TRUE);

    foreach($items as $key => $row) {
        $this->your_model->insert_new($row, $job_status[$key], $stati[$key]);
    }
}

your_model中,编写数据库查询以在需要的任何位置插入这些数据。当然,您需要更改名称 - methodcontrolleryour_model以适合您的应用。