我有一组数据存储在数据库表中tb_Alt,如下所示:
id_alt |name|distance|price|quantity
1 |A | 2 | 10 | 3
2 |B | 4 | 123 | 4
3 |C | 1 | 201 | 1
4 |D | 5 | 145 | 10
而且tb_Cri,如下所示:
id_criteria |name | weight |
1 |distance | 10
2 |price | 20
3 |quantity | 30
现在,我想从动态数据插入tb_A到tb_B具有结构如下:
# |id_alt | id_criteria | value
1 | 1 | 1 | 2
2 | 1 | 2 | 10
3 | 1 | 3 | 3
4 | 2 | 1 | 4
5 | 2 | 2 | 123
6 | 2 | 3 | 4
7 | 3 | 1 | 1
8 | 3 | 2 | 201
9 | 3 | 3 | 1
10| 4 | 1 | 5
11| 4 | 2 | 145
12| 4 | 3 | 10
我如何通过 PHP 实现这一目标?
这是我到目前为止尝试过的:
$data = $obj->selTable("SELECT * FROM tbb_Alt");
//$finishArr = transposeArr($data);
$totalLoop = count($data)*3;
$interval = (int)$totalLoop/3;
$counter = $totalLoop+$interval;
$j = 0;
$k = 0;
for($i=0;$i<=$counter;$i++){
if($i%4 !== 0){
if($k%4 == 0) $k=1;
// code to insert data into tb_B
// the part where i got stuck
echo $j.' '.$k++.' ';
continue;
}
$j++;
}