2013-10-31 6 views
0

저는 Code Igniter.i의 초보자입니다. 업데이트시 특정 행을 업데이트하려고합니다.codeigniter에서 특정 행을 업데이트하는 방법은 무엇입니까?

도와주세요.

내보기 파일

<div id="wrapper"> 
<div id="form"> 
<?php $query=$this->mod1->about_display()?> 
<?php if($query){ ?> 
<?php echo form_open('textarea/update_testimonial'); ?> 
<?php foreach($query as $row){ ?> 
<textarea name="update"><?php echo $row->testi; ?></textarea> 
<input type="submit" name="sub" value="UPDATE" /> 
</form> 
<?php } 

    } 
?> 
</div> 
</div> 

내 컨트롤러 파일

function update_testimonial(){ 

    $id = $this->input->get('id'); 
    $this->load->model('mod1'); 
    $this->mod1->about_display($id); 


} 

내 모델 파일

function about_display(){ 
$id = $this->input->get('id'); 
$query=$this->db->where('id', $id); 
    $this->db->get('testimonials'); 
    if($query->num_rows()>0){ 
     return TRUE; 
    }else{ 
     return FALSE; 
    } 

}

그래서 그것을 할 수있는 나에게 간단한 예를주십시오 . 나는 CI에서 아주 새롭다. 제발 도와주세요. 주셔서 감사합니다

+2

더 나은 문서 확인 ... –

답변

1

컨트롤러 :

function update_testimonial(){ 
    $update = $this->input->post('update', True); 
    $id = (int) $this->input->get('id', False); ### THIS MAY need to be a $this->input->post() 
    $this->load->model('mod1'); 
    $this->mod1->update_display($update, $id); 
} 

모델 : 기본적으로

function update_display($update, $id) { 
    $this->load->database(); 
    $this->db->where('id', $id); 
    $update = array('testi', $update); 
    $this->db->update('testimonials', $update); 
} 

당신이 양식에서 $_POST 변수를 당겨 모델로 보내고,에 CodeIgniter를의 $this->db->update() 기능을 사용 그 단일 행을 업데이트하십시오. 양식에 <form type="hidden" name="id" />을 추가하면 두 변수가 모두 POST을 통해 들어올 수 있습니다.

관련 문제