2014-09-21 83 views
-1

使用codeigniter模型插入和检索包含数组的数据。在插入检索数据中插入检索数据codeigniter模型

型号:

function abc { 

    $tomorrow_date=$this->input->post('datee'); 
    $id=$this->input->post('id'); 

    $this -> db -> select('name,phone,address,age'); 
    $this -> db -> from('user_reg'); 
    $this -> db -> where('patient_id',$id); 
    $this -> db -> where('date',$tomorrow_date); 
    $query = $this -> db -> get(); 

    if ($query->num_rows() > 0) 
    { 
    $row = $query->row(); 

    } 

我想插入如:

$data = array( 
       'date'=>$tomorrow_date, 
       'name'=>$name, 
       'phone'=>$phone, 
       'address'=>$address, 
       'age'=>$age, 
       'patient_id'=>id, 



       ); 
    $this->db->insert('user_info',$data); 
} 

我怎样才能插入数据?

回答

0
function abc { 

    $tomorrow_date=$this->input->post('datee'); 
    $id=$this->input->post('id'); 

    $this -> db -> select('name,phone,address,age'); 
    $this -> db -> from('user_reg'); 
    $this -> db -> where('patient_id',$id); 
    $this -> db -> where('date',$tomorrow_date); 
    $query = $this -> db -> get()->row_array(); 

    if ($query->num_rows() > 0){ 

     $data = array( 
      'date'=>$tomorrow_date, 
      'name'=>$query['name'], 
      'phone'=>$query['phone'], 
      'address'=>$query['address'], 
      'age'=>$query['age'], 
      'patient_id'=>$id 
     ); 
    } 

    $this->db->insert('user_info',$data); 
}