我想從表2中插入數據到table1,其中table2中的數據與表3中的值相乘。從其他表中插入選擇乘法
Table 1和Table具有相同的列(ID,rangking,狀態,接入,設施,普及)(ID是自動遞增) 表2中有數據:
ID |正在拉動|狀態|訪問|設施|人氣
1 | 9 | 4 | 2 | 4 | 6
2 | 4 | 5 | 1 | 2 | 7
3 | 5 | 8 | 5 | 3 | 4
table3有數據:
id |值
c2 | 0.2
c3 | 0.5
c4 | 0.1
c5 | 0.3
$sql = mysqli_query ($koneksi, "SELECT value
FROM table3 WHERE id ='c2'") or die(mysqli_error($koneksi));
$c2 = mysqli_fetch_array($sql);
$sql = mysqli_query ($koneksi, "SELECT value
FROM table3 WHERE id ='c3'") or die(mysqli_error($koneksi));
$c3 = mysqli_fetch_array($sql);
insert into table1 (rangking,status,access,facility,popularity)
SELECT (rangking*$c2['value'] as Rank,status *$c3['value'] as Stat,access,facility,popularity) FROM table2
從那個查詢我發現錯誤,有什麼幫助嗎?
仍然註釋= mysqli_error()期望的是1個參數,0給 – Hafidh
這個錯誤是不相關的我答案...我只發佈查詢SQL代碼,而不是mysqli_query ..代碼..在哪個查詢你指? – scaisEdge
沒有()的SELECT命令..我把自己弄糊塗了。 Thx爲您提供幫助! – Hafidh