嗨,我想插入2個陣列在數據庫表中,並得到以下:不能插入數組表MySQL的PHP
Warning: Invalid argument supplied for foreach() in
C:\xampp\htdocs\sport\admin\model\competition\newsletter.php on line 9
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\sport\admin\model\competition\newsletter.php on line 12
Notice: Array to string conversion in C:\xampp\htdocs\sport\admin\model\competition\newsletter.php on line 18
Notice: Array to string conversion in C:\xampp\htdocs\sport\admin\model\competition\newsletter.php on line 18Notice: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''customer_transaction'(customer_id,amount) VALUES'Array,Array'' at line 1
Error No: 1064
INSERT INTO 'customer_transaction'(customer_id,amount) VALUES'Array,Array' in C:\xampp\htdocs\sport\system\database\mysql.php on line 49
如何解決這一切。下面是代碼: 這是Opencart的模塊文件
$sql = "SELECT DISTINCT competition_rate, customer_id FROM " . DB_PREFIX . "customer WHERE competition_rate NOT LIKE 0";
$query = $this->db->query($sql);
$rates = array();
$customer_ids = array();
foreach($query->row['competition_rate'] as $result){
$rates[] = $result * $data['name'];
}
foreach($query->row['customer_id'] as $result2){
$customer_ids[] = $result2;
}
$sums = $rates;
$ids = $customer_ids;
$this->db->query("INSERT INTO 'customer_transaction'(customer_id,amount) VALUES'".$ids.",".$sums."'");
}
警告:非法字符串偏移'customer – user3343374
對不起,我錯誤地寫了$ query- >行而不是$ query-> rows,我現在編輯它。 –
非常感謝! – user3343374