在我的應用程序控制器中,我有一個方法transaction_reimburse()
,它接收到的id爲POST
字符串值。該方法的功能是獲取與數據庫中的id匹配的所有事務,並相應地更新它們。在Codeigniter中從數據庫中檢索和更新數據時出錯
控制器方法:
public function transaction_reimburse() {
$reimburse = array('reimburse' => 1);
$transactions = $this->Transaction_model->get_these_ids($this->input->post('ids'));
$this->Transaction_model->reimburse_these($transactions, $reimburse);
}
模型方法:
function get_these_ids($ids) {
$this->db->select('tbl_user.name as uname, tbl_transactions.participant_id as pid, tbl_transactions.card_number as card_no, tbl_transactions.group as ugroup, tbl_toilet.name as utoilet, tbl_transactions.amount_paid as u_amount, tbl_transactions.toilet_price as t_price, tbl_transactions.reimburse_amount as r_amount, tbl_transactions.details as u_details');
$this->db->from('tbl_transactions');
$this->db->join('tbl_user', 'tbl_user.participant_id = tbl_transactions.participant_id', 'left');
$this->db->join('tbl_toilet', 'tbl_toilet.toilet_code = tbl_transactions.toilet_code', 'left');
$this->db->where("tbl_transactions.id IN (". $ids .")");
return $this->db->get();
}
模型方法:
不過,我收到以下錯誤:
A PHP Error was encountered
Severity: 4096
Message: Object of class CI_DB_mysql_result could not be converted to string
Filename: models/transaction_model.php
Line Number: 450
A Database Error Occurred
Error Number: 1064
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 ')' at line 1
UPDATE `tbl_transactions` SET `reimburse` = 1 WHERE `tbl_transactions`.`id` IN()
Filename: C:\xampp\htdocs\ipa\system\database\DB_driver.php
Line Number: 330
我需要知道的是爲什麼會出現這些錯誤是什麼?
所以問題是?? –
POST ID的格式是什麼? – Shomz
您能否詳細說明$ ids forrmat?數組或可能是其他可能性 –