使用1按钮更新数据库中的所有字段

时间:2014-01-08 13:30:47

标签: php codeigniter

我有一个存储在数据库中的项目列表,我在表格中打印这些项目但是每个项目的名称都可以在输入字段中更改,问题是当我更改每个项目的名称并按下按钮“更新”然后最后一个值“名称”在每个项目上更新。如何用hes唯一名称更新每个项目?这是我的代码,我希望描述清楚。

查看

<form role="form" action="<?php echo base_url();?>CRUD/voegcategorietoe" method="post" enctype="multipart/form-data">
             <table class="table table-striped">
                 <?php foreach($allGallery as $row) { ?>
                 <tr>
                     <td><img height="80" src="<?php echo base_url(); ?>/uploads/<?php echo $row->gallery_img; ?>" alt=""/></td>
                     <td>name: <input type="text" class="form-control kort" name="name" value="<?php echo $row->order; ?>" required></td>
                     <td>Titel: <?php echo $row->titel; ?></td>
                     <td>Period: <?php echo $row->period; ?></td>
                     <td>Size: <?php echo $row->size; ?></td>
                     <td>Info: <?php echo $row->info; ?></td>
                     <td><?php echo anchor("site/delete/$row->gallery_id",'X') ?></td>
                 </tr>
                 <?php }?>
             </table> 
             <button type="submit" class="btn btn-default">Update</button>
         </form>

控制器

 function updategallery() {
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '1000';
    $config['max_width']  = '3024';
    $config['max_height']  = '3768';
    $this->load->library('upload', $config);

        if ( ! $this->upload->do_upload())
    {
        $error = array('error' => $this->upload->display_errors());
    }   

    $datap = array('upload_data' => $this->upload->data());
    $data = array();
    if( $this->input->post('name') != "" ) $data['name'] = $this->input->post('name');
    $this->Cms_model->update_gallery($data);    
    redirect('home#gallery','refresh');     

 }

模型

 function update_gallery($data)  
{  
    $this->db->update('tblgallery', $data);
} 

0 个答案:

没有答案