我有一张桌子(即)payments
(Pay_ID
,Order_ID
,User_ID
,Bank_Name
,Account_No
,{{1} },Total_Amount
,Paid_Amount
,Remaining_Amount
我用这段代码更新了表格
DateTime
这里在$ sess_id中我将MAX(public function update()
{
$sess_id = $this->session->userdata('tot_amnt');
$Bank_Name = $this->input->post('Bank_Name');
$Account_No = $this->input->post('Account_No');
$Paid_Amount = $this->input->post('Paid_Amount');
$qq = "UPDATE `payments`
SET Bank_Name = '".$Bank_Name."',
Account_No = '".$Account_No."',
Paid_Amount = '".$Paid_Amount."',
Remaining_Amount = '".$sess_id."' - '".$Paid_Amount."'
ORDER BY `DateTime` DESC LIMIT 1";
return $this->db->query($qq);
}
)存储在控制器(i-e)中的DateTime
表中
payments
现在每件事情都运转正常,但它给我看了两个错误, 第一个错误:pay_model行No:22中的数组到字符串转换:
$query = $this->db->query('SELECT `Total_Amount` FROM `payments` WHERE `DateTime` = (SELECT MAX(DateTime) FROM `payments`)')->result();
$new_data=array(
'tot_amnt' => $query
);
$this->session->set_userdata($new_data);
答案 0 :(得分:0)
我猜您的$sess_id
实际上是一个数组,因此会打印单词Array
,这就是Remaining_Amount
中的计算类似于Array - 200 = -200
的原因。
我发现$sess_id
来自$sess_id = $this->session->userdata('tot_amnt');
,所以您可能已经分配了tot_amnt
值
$tot_amnt = array(
'tot_amnt' => 1112
);
$this->session->set_userdata($tot_amnt);
相反,您可以一次添加userdata一个值:
$this->session->set_userdata('tot_amnt ', 1112);