配列を mysql テーブルに挿入する必要があります。角かっこのある行は、挿入する必要があるものの例です。
Array
(
[0] => Array
(
[batch_id] => 1
[seq_id] => 1
[q_id] => 2046
[a1] => 0
[a2] => 1
[a3] => 2
[a4] => 3
[a5] => 4
)
[1] => Array
(
[batch_id] => 1
[seq_id] => 2
[q_id] => 2046
[a1] => 0
[a2] => 2
[a3] => 1
[a4] => 3
[a5] => 4
)
[2] => Array
(
[batch_id] => 1
[seq_id] => 3
[q_id] => 2046
[a1] => 2
[a2] => 0
[a3] => 2
[a4] => 2
[a5] => 1
)
テーブル:
id | r_id | q_id | c_id | ranking
-------------------------------------------
18965| 2205 | 2046 | a1 | 0
18966| 2205 | 2046 | a2 | 2
18967| 2205 | 2046 | a3 | 3
18968| 2205 | 2046 | a4 | 1
18969| 2205 | 2046 | a5 | 4
19965| 2214 | 2046 | a1 | 0
19966| 2214 | 2046 | a2 | 1
19967| 2214 | 2046 | a3 | 1
19968| 2214 | 2046 | a4 | 2
19969| 2214 | 2046 | a5 | 3
(20965)| (11) | (2046) | (a1) | (0)
(20966)| (11) | (2046) | (a2) | (1)
(20967)| (11) | (2046) | (a3) | (2)
(20968)| (11) | (2046) | (a4) | (3)
(20969)| (11) | (2046) | (a5) | (4)
(21965)| (12) | (2046) | (a1) | (0)
(21966)| (12) | (2046) | (a2) | (2)
(21967)| (12) | (2046) | (a3) | (1)
(21968)| (12) | (2046) | (a4) | (3)
(21969)| (12) | (2046) | (a5) | (4)
(22965)| (13) | (2046) | (a1) | (2)
(22966)| (13) | (2046) | (a2) | (0)
(22967)| (13) | (2046) | (a3) | (2)
(22968)| (13) | (2046) | (a4) | (2)
(22969)| (13) | (2046) | (a5) | (1)
この方法で挿入したい場合は、挿入ステートメントでループを使用していますか? Table.id は自動インクリメントで、r_id は batch_id+seq_id です。
$result = $this->query("Select * from table_3");
$new_insert = array();
$csvr[] = $this->fetch_array($result);
foreach($csvr as $cr){
$ir_id = $cr['batch_id'].$cr['seq_id'];
$q_id = $cr['q_id'];
$query1 = "insert into t1 (id, survey_id, submitted) value ('$ir_id', '85',time());";
$this->query($query1);
foreach ($cr as $k => $v){
if(preg_match('{^a\d+$}',$k)){
$new_insert[] = array(
'r_id'=>$ir_id,
'q_id' =>$q_id,
'c_id' =>$k,
'ranking'=>$v
);
$query2 = "insert into Table (r_id, q_id, c_id, ranking) value ('r_id', 'q_id','c_id','ranking')";
$this->query($query2);
}
}
}
私はそれを行う方法がわかりません.....誰かが私を助けることができますか?