dongyan5141 2014-08-08 08:01
浏览 39

将数组存储在数据库中

I have three arrays example: $array1,$array2,$array3.

I want to insert the array2 and array3 in two different columns in the same table. can i do that?

here is the code below that i am trying but it does not work for me i am doing in codeigniter:

  • controller:

     $athletes_id = $this->input->post('athletes'); // array 1
     $fields_id = $this->input->post('fields_id');  // array 2
     $athlete_score = $this->input->post('athlete_score');  // array 3
    
    
     $id = array();
     foreach($athlete_score as $row){
     $additional_data = array(
     'test_reports_id' => $test_report_id,
     'score' => $row,
     );
     $id[] = $this->test_model->save_test_reports_details($additional_data);
     }
     for($j=0;$j<count($fields_id);$j++){
     $data2 = array('fields_id' => $fields_id[$j]);
     $this->test_model->update_test_reports_details($id,$data2);
     }
    
  • Model :

       public function update_test_reports_details($id,$data2){
       $this->db->where_in('id',$id);
       $this->db->update('test_reports_details',$data2);
       }
    
  • 写回答

3条回答 默认 最新

  • dti70601 2014-08-08 08:07
    关注

    Just serialize the arrays.

    $data2 = serialize($array2); // or whatever array you want to store
    

    Then to retrieve with unserialize

    $array2 = unserialize($data2);//or the row index  
    
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改