2013-05-19 3 views
0

으로 저장 나는 다음과 같은 기능이 있습니다기존 배열에 배열을 추가 이그나이터

function saveCOA() { 
    $labref = $this->uri->segment(3); 
    $data = $this->input->post('compedia'); 
    $data1 = $this->input->post('specification'); 
    count($data) == count($data1); 
    for ($i = 0; $i < count($data); $i++) { 
     $insert_data = array(
      'labref' => $labref, //NDQA201303001     
      'compedia' => $data[$i], 
      'specification' => $data1[$i] 
     ); 
     $this->db->insert('coa_body', $insert_data); 
    } 

이 잘 저장하지만 아래 그림과 같이 지금은 그것을 수정 한을 : 값

$labref=$this->uri->segment(3); 
$test_id= $this->getRequestedTestIds($labref); 
$data = $this->input->post('compedia'); 
$data1 = $this->input->post('specification'); 
count($data) == count($data1) && count($data)== count($test_id); 
for ($i = 0; $i < count($data); $i++) { 
    $insert_data = array(
     'labref' => $labref, //NDQA201303001 - Same for all the rows 
     'test_id'=>$test_id[$i], //added array 
     'compedia' => $data[$i], 
     'specification' => $data1[$i] 
    ); 
    $this->db->insert('coa_body', $insert_data); 
} 

$ test_id 같이 print_r() 의해 인쇄된다 :

Array ([0] => Array ([test_id] => 5) [1] => Array ([test_id] => 7) [2] => Array ([test_id] => 9) [3] => Array ([test_id] => 10)) 

I 배열추가 한이며, 다음을 반환합니다.

Error Number: 1054 

Unknown column 'Array' in 'field list' 

INSERT INTO `coa_body` (`labref`, `test_id`, `compedia`, `specification`) VALUES ('NDQA201303001', Array, 'Alphy', 'poxy') 

Filename: C:\xampp\htdocs\NQCL\system\database\DB_driver.php 

Line Number: 330 

무엇이 누락 되었습니까?

답변

1

$test_id[$i] 또는 $test_id[0]은 키 test_id이 포함 된 배열이므로 mysql 쿼리에 배열을 제공합니다. 대신 다음을 수행하십시오.

'test_id' => $test_id[$i]['test_id'], //added array 

예 : print_r($test_id[0])은 다음을 제공합니다 :

Array ([test_id] => 5) 

나는 당신이 그것을 얻길 바랍니다. 좋은 하루 되세요.

+0

고마워요, 잘 작동합니다. – alphy

+0

안녕하세요. 프로젝트에 행운을 빈다. –

관련 문제